<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Taming Serpents and Pachyderms</title>
	<atom:link href="http://pyrseas.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://pyrseas.wordpress.com</link>
	<description>Musings on Python, PostgreSQL and other species</description>
	<lastBuildDate>Fri, 17 May 2013 20:18:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='pyrseas.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Taming Serpents and Pachyderms</title>
		<link>http://pyrseas.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://pyrseas.wordpress.com/osd.xml" title="Taming Serpents and Pachyderms" />
	<atom:link rel='hub' href='http://pyrseas.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Pyrseas contributions solicited</title>
		<link>http://pyrseas.wordpress.com/2013/05/17/pyrseas-contributions-solicited/</link>
		<comments>http://pyrseas.wordpress.com/2013/05/17/pyrseas-contributions-solicited/#comments</comments>
		<pubDate>Fri, 17 May 2013 18:48:31 +0000</pubDate>
		<dc:creator>jma</dc:creator>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Version control]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[version control]]></category>

		<guid isPermaLink="false">http://pyrseas.wordpress.com/?p=2019</guid>
		<description><![CDATA[Do you use PostgreSQL and truly believe it&#8217;s &#8220;the world&#8217;s most advanced open source database&#8221; and that its upcoming 9.3 release will make it even more awesome? Do you also use Python and believe it&#8217;s &#8220;an easy to learn, powerful &#8230; <a href="http://pyrseas.wordpress.com/2013/05/17/pyrseas-contributions-solicited/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pyrseas.wordpress.com&#038;blog=19437126&#038;post=2019&#038;subd=pyrseas&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Do you use <a href="http://www.postgresql.org/">PostgreSQL</a> and truly believe it&#8217;s &#8220;the world&#8217;s most advanced open source database&#8221; and that its upcoming 9.3 release will make it even more awesome?</p>
<p>Do you also use <a href="http://www.python.org/">Python</a> and believe it&#8217;s &#8220;an easy to learn, powerful programming language&#8221; with &#8220;elegant syntax&#8221; that makes it an ideal language for developing applications and tools around PostgreSQL, such as Pyrseas?</p>
<p>Then we could use your help. For starters, we want to add support for the <a href="https://github.com/jmafc/Pyrseas/issues/55">MATERIALIZED VIEWs</a> and <a href="https://github.com/jmafc/Pyrseas/issues/56">EVENT TRIGGERs</a> coming up in PG 9.3.</p>
<p>We have also been requested to add the capability to load and maintain &#8220;static data&#8221; (relatively small, unchanging tables) as part of <a href="http://pyrseas.readthedocs.org/en/latest/yamltodb.html">yamltodb</a>, so that it can be integrated more easily into database version control workflows.</p>
<p>And for the next release, Pyrseas 0.7, we&#8217;d like to include the first version of the <a href="https://github.com/jmafc/Pyrseas/issues/17">database augmentation tool</a> which will support declarative implementation of business logic in the database&#8211;starting off with audit trail columns. Some work has been done on this already, but it needs integration with the current code and tests.</p>
<p>Or perhaps coding is not your forte, but you&#8217;re really good at explaining and documenting technical &#8220;stuff&#8221;. Then you could give us a hand with revamping the <a href="http://pyrseas.readthedocs.org/en/latest/">docs</a>, maybe writing a tutorial so that users have a smooth ride using our tools.</p>
<p>Or maybe you have your own ideas as to how improve the PostgreSQL version control experience. We&#8217;d love to hear those too.</p>
<p>If you&#8217;d like to help, you can <a href="https://github.com/jmafc/Pyrseas">fork the code on GitHub</a>, join the <a href="http://lists.pgfoundry.org/mailman/listinfo/pyrseas-general">mailing list</a> and introduce yourself, or leave a comment below.</p>
<br />Filed under: <a href='http://pyrseas.wordpress.com/category/postgresql-2/'>PostgreSQL</a>, <a href='http://pyrseas.wordpress.com/category/python/'>Python</a>, <a href='http://pyrseas.wordpress.com/category/version-control/'>Version control</a>  <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pyrseas.wordpress.com&#038;blog=19437126&#038;post=2019&#038;subd=pyrseas&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://pyrseas.wordpress.com/2013/05/17/pyrseas-contributions-solicited/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0d235d4094b8dbf2cd9932667d828795?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jmafc</media:title>
		</media:content>
	</item>
		<item>
		<title>Tuples in the Pythonic, TTM-inspired interface to PostgreSQL</title>
		<link>http://pyrseas.wordpress.com/2013/03/26/tuples-in-the-pythonic-ttm-inspired-interface-to-postgresql/</link>
		<comments>http://pyrseas.wordpress.com/2013/03/26/tuples-in-the-pythonic-ttm-inspired-interface-to-postgresql/#comments</comments>
		<pubDate>Tue, 26 Mar 2013 18:18:08 +0000</pubDate>
		<dc:creator>jma</dc:creator>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[User interfaces]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[ttm]]></category>
		<category><![CDATA[user interfaces]]></category>

		<guid isPermaLink="false">http://pyrseas.wordpress.com/?p=1947</guid>
		<description><![CDATA[The Third Manifesto formally describes tuple types (RM prescription 6), tuple values (prescription 9), tuple variables (prescription 12) as well as other tuple-related elements. As mentioned in the previous post, a tuple value is a set of ordered triples each &#8230; <a href="http://pyrseas.wordpress.com/2013/03/26/tuples-in-the-pythonic-ttm-inspired-interface-to-postgresql/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pyrseas.wordpress.com&#038;blog=19437126&#038;post=1947&#038;subd=pyrseas&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.dcs.warwick.ac.uk/~hugh/TTM/TTM-2013-02-07.pdf">The Third Manifesto</a> formally describes <strong>tuple types</strong> (RM prescription 6), <strong>tuple values</strong> (prescription 9), <strong>tuple variables</strong> (prescription 12) as well as other tuple-related elements. As mentioned in the <a title="Attributes in the Pythonic, TTM-inspired interface to PostgreSQL" href="http://pyrseas.wordpress.com/2013/03/21/attributes-in-the-pythonic-ttm-inspired-interface-to-postgresql/">previous post</a>, a tuple value is a set of ordered triples each consisting of attribute name, type and value.</p>
<p>Class <a href="https://github.com/jmafc/Pyrseas/blob/master/pyrseas/relation/tuple.py">Tuple</a> of the <a title="A Pythonic, TTM-inspired interface to PostgreSQL – Requirements" href="http://pyrseas.wordpress.com/2013/03/07/a-pythonic-ttm-inspired-interface-to-postgresql-requirements/">TTM-inspired interface to PostgreSQL</a> models TTM tuples as Python lists of TTM <a href="https://github.com/jmafc/Pyrseas/blob/master/pyrseas/relation/attribute.py">Attribute</a> objects. Lists were used rather than sets because for many practical purposes the order of the attributes is useful (or has &#8220;meaning&#8221;), e.g., the first attribute listed is most often –even in purist relational theory presentations– the primary key or part of the primary key.</p>
<p>The interface stores the Tuple <strong>heading</strong> as a (Python) n-tuple of name-type tuples, in the &#8220;internal use&#8221; <em>_heading</em> attribute. The n-tuple was chosen over a list due to its immutability. The interface also sets each Attribute as a Python attribute of the Tuple object. Thus, if you define a Tuple variable as follows:</p>
<pre>film = Tuple([
    Attribute('id', int, sysdefault=True),
    Attribute('title'),
    Attribute('release_year', int)])</pre>
<p>You can then assign or access an Attribute using simple Python syntax:</p>
<pre>film.title = "Seven Samurai"
if film.year == 1954:
    <em>do something</em></pre>
<p>The interface also stores two other internal use lists, one for nullable attributes and another for attributes that allow default values. These are to be used by upstream classes such as RelVar.</p>
<p>Class Tuple has a <em>__setattr__</em> method tailored to deal with assignment to TTM Attributes. It disallows assignment to internal attributes after initialization, with one exception: the <em>_tuple_version</em> attribute (used by RelVar for optimistic concurrency). It also doesn&#8217;t allow assignment to undefined Attributes, e.g., given the <em>film</em> variable above, attempting to assign to <em>film.length</em> will raise an AttributeError. Finally, the assignment is &#8220;filtered&#8221; through class Attribute, so that an attempt such as <em>film.title = 8.5</em> will result in a ValueError from that class.</p>
<p>The pyrseas.relation.tuple module defines a standalone function: <em>tuple_values_dict</em>. This is used to generate a dictionary of attribute values suitable for passing to Psycopg&#8217;s cursor.execute method. For INSERT, a single <em>currtuple</em> argument is expected. For UPDATE, the modified Tuple is passed as a second argument and <em>tuple_values_dict</em> will return a dictionary solely for the attribute and values that have changed.</p>
<br />Filed under: <a href='http://pyrseas.wordpress.com/category/postgresql-2/'>PostgreSQL</a>, <a href='http://pyrseas.wordpress.com/category/python/'>Python</a>, <a href='http://pyrseas.wordpress.com/category/user-interfaces/'>User interfaces</a>  <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pyrseas.wordpress.com&#038;blog=19437126&#038;post=1947&#038;subd=pyrseas&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://pyrseas.wordpress.com/2013/03/26/tuples-in-the-pythonic-ttm-inspired-interface-to-postgresql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0d235d4094b8dbf2cd9932667d828795?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jmafc</media:title>
		</media:content>
	</item>
		<item>
		<title>Attributes in the Pythonic, TTM-inspired interface to PostgreSQL</title>
		<link>http://pyrseas.wordpress.com/2013/03/21/attributes-in-the-pythonic-ttm-inspired-interface-to-postgresql/</link>
		<comments>http://pyrseas.wordpress.com/2013/03/21/attributes-in-the-pythonic-ttm-inspired-interface-to-postgresql/#comments</comments>
		<pubDate>Thu, 21 Mar 2013 17:27:59 +0000</pubDate>
		<dc:creator>jma</dc:creator>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[User interfaces]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[ttm]]></category>
		<category><![CDATA[user interfaces]]></category>

		<guid isPermaLink="false">http://pyrseas.wordpress.com/?p=1945</guid>
		<description><![CDATA[The Third Manifesto&#8216;s Relational Model (RM) prescription 9 defines a relation heading as &#8220;a set of ordered pairs or attributes of the form &#60;A,T&#62;,&#8221; where A is the name of the attribute and T is the name of the declared &#8230; <a href="http://pyrseas.wordpress.com/2013/03/21/attributes-in-the-pythonic-ttm-inspired-interface-to-postgresql/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pyrseas.wordpress.com&#038;blog=19437126&#038;post=1945&#038;subd=pyrseas&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.dcs.warwick.ac.uk/~hugh/TTM/TTM-2013-02-07.pdf">The Third Manifesto</a>&#8216;s Relational Model (RM) prescription 9 defines a relation heading as &#8220;a set of ordered pairs or <strong>attributes</strong> of the form &lt;<em>A,T</em>&gt;,&#8221; where <em>A</em> is the name of the attribute and <em>T</em> is the name of the declared type of the attribute<em></em><em></em>. It then defines a <strong>tuple value</strong> (or <strong>tuple</strong> for short) as a set of ordered triples of form &lt;<em>A,T,v</em>&gt; where <em>v</em> is an arbitrary value of type <em>T</em>, called the <em></em><strong>attribute value</strong>.</p>
<p>Class <a href="https://github.com/jmafc/Pyrseas/blob/master/pyrseas/relation/attribute.py">Attribute</a> of the <a title="A Pythonic, TTM-inspired interface to PostgreSQL – Requirements" href="http://pyrseas.wordpress.com/2013/03/07/a-pythonic-ttm-inspired-interface-to-postgresql-requirements/">TTM-inspired interface to PostgreSQL</a> models the latter ordered triple rather than the ordered pair. I considered implementing the pair, say as AttribType, and deriving Attribute from it, but opted for the leaner, no-hierarchy solution for now.</p>
<p>An Attribute object should be initialized with a name, Python type and a value. However, only the name is required. The default type is <em>str</em> and for Python 2, <em>unicode</em> is treated almost as a synonym for <em>str</em> (I realize this goes against everything that your mother taught you, but I&#8217;m hoping that widespread Python 3 adoption will make this moot soon).</p>
<p>I wholehearteadly agree with TTM RM proscription 5 banning attributes that do not have a value, i.e., like SQL <em>NULL</em>s. However, I hope the interface is useful on existing databases, so in the interest of practicality, class Attribute has two additional, optional arguments: <em>nullable</em> and <em>sysdefault</em>. The former is to specify that an attribute allows NULLs (or<em></em> <em>None</em> in Python). The latter can be used to indicate the corresponding table column has an SQL DEFAULT specification (this includes those defined as SERIAL or BIGSERIAL).</p>
<p>If an attribute is not <em>nullable</em> and not <em>sysdefault</em>, a value must be specified. If omitted, a suitable default is created based on the type (if possible), i.e., an empty string for <em>str</em>, 0 for <em>int</em>, 0.0 for <em>float</em>. If the attribute is <em>nullable</em>, empty string, 0 or 0.0 are converted to <em>None</em>. This approach is to facilitate dealing with empty HTML form fields, i.e., if the user skips a <em>nullable</em> field, the attribute should end up as a NULL in the database.</p>
<p>If a value is provided, the code raises ValueError if the value does not agree with the specified (or defaulted) Python type. The only exceptions are that an <em>int</em> value is cast to <em>float</em>, and a <em>unicode</em> value is allowed if the type is <em>str</em> and we&#8217;re working in Python 2.x.</p>
<br />Filed under: <a href='http://pyrseas.wordpress.com/category/postgresql-2/'>PostgreSQL</a>, <a href='http://pyrseas.wordpress.com/category/python/'>Python</a>, <a href='http://pyrseas.wordpress.com/category/user-interfaces/'>User interfaces</a>  <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pyrseas.wordpress.com&#038;blog=19437126&#038;post=1945&#038;subd=pyrseas&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://pyrseas.wordpress.com/2013/03/21/attributes-in-the-pythonic-ttm-inspired-interface-to-postgresql/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0d235d4094b8dbf2cd9932667d828795?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jmafc</media:title>
		</media:content>
	</item>
		<item>
		<title>A Pythonic, TTM-inspired interface to PostgreSQL &#8211; Requirements</title>
		<link>http://pyrseas.wordpress.com/2013/03/07/a-pythonic-ttm-inspired-interface-to-postgresql-requirements/</link>
		<comments>http://pyrseas.wordpress.com/2013/03/07/a-pythonic-ttm-inspired-interface-to-postgresql-requirements/#comments</comments>
		<pubDate>Thu, 07 Mar 2013 05:07:10 +0000</pubDate>
		<dc:creator>jma</dc:creator>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[User interfaces]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[ttm]]></category>
		<category><![CDATA[user interfaces]]></category>

		<guid isPermaLink="false">http://pyrseas.wordpress.com/?p=1597</guid>
		<description><![CDATA[Several moons ago, I started a series of posts about &#8220;designing and implementing a generic end user interface for PostgreSQL.&#8221; After a while, the series got sidetracked by other issues. More recently, I have returned to the original endeavor. Partly &#8230; <a href="http://pyrseas.wordpress.com/2013/03/07/a-pythonic-ttm-inspired-interface-to-postgresql-requirements/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pyrseas.wordpress.com&#038;blog=19437126&#038;post=1597&#038;subd=pyrseas&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Several moons ago, I <a title="User Interfaces for Databases" href="http://pyrseas.wordpress.com/2011/05/23/user-interfaces-for-databases/">started</a> a series of posts about &#8220;designing and implementing a generic end user interface for PostgreSQL.&#8221; After a while, the series got sidetracked by <a title="Business Logic in the Database" href="http://pyrseas.wordpress.com/2012/01/02/business-logic-in-the-database/">other</a> <a title="Python Web Frameworks – Candidates" href="http://pyrseas.wordpress.com/2011/12/26/python-web-frameworks-candidates/">issues</a>.</p>
<p>More recently, I have returned to the original endeavor. Partly from reading <a href="http://www.amazon.com/gp/product/1426937237/ref=as_li_tf_tl?ie=UTF8&amp;camp=1789&amp;creative=9325&amp;creativeASIN=1426937237&amp;linkCode=as2&amp;tag=freedomcircle">Database Explorations: Essays on <em>The Third Manifesto</em> and related topics</a><img style="border:none!important;margin:0!important;" alt="" src="http://www.assoc-amazon.com/e/ir?t=freedomcircle&amp;l=as2&amp;o=1&amp;a=1426937237" width="1" height="1" border="0" /> by C.J. Date and Hugh Darwen, I decided to use relational concepts as presented in <a href="http://www.thethirdmanifesto.com/"><em>The Third Manifesto</em></a> (TTM) in my implementation. This post provides an overview of the requirements.</p>
<h2>Limited Scope</h2>
<p>The interface is not a full-blown replacement for an object-relational mapper (ORM) (although in theory it could eventually grow in that direction). The interface is intended to assist with two typical needs of a database &#8220;admin&#8221; application: browsing and CRUD.</p>
<p>Browsing refers to presenting a subset of rows (<strong>tuples</strong>) of a table (relation variable or <strong>relvar</strong>) for subsequent editing. The relvar will typically be normalized so it may be necessary to <em>join</em> it to other relvars. Browsing will usually display a limited number of columns (<strong>attributes</strong><strong></strong>) so relational <em>projection</em> will be needed.</p>
<p>CRUD refers to the ability to create, read, update and delete single tuples in a relvar. The interface should only support relvars with a properly defined, possibly composite primary <strong>key</strong>.</p>
<h2><em></em>Simplicity</h2>
<p>The user (developer) should have to define only the attributes of each relvar together with the key, and for browsing, the projected attributes plus a <em></em>JOIN specification if multiple relvars are involved. The definitions should be simple enough so that most of them could be (at a later date) derived automatically from the database catalogs.</p>
<p>From the definitions, the interface should generate all necessary SQL commands to INSERT a single tuple (possibly returning a generated key value), retrieve, UPDATE or DELETE a single tuple using the key, and fetch subsets of projected/joined tuples in a given order.</p>
<h2>Optimistic Concurrency Control</h2>
<p>The interface should take advantage of PostgreSQL features to implement optimistic locking when handling updates or deletes, as described in a <a title="The Phantom of the Database – Part 4" href="http://pyrseas.wordpress.com/2012/01/13/the-phantom-of-the-database-part-4/">previous series of posts</a>.</p>
<h2>Query by Example Support</h2>
<p>The interface should facilitate querying of the browsed tuples using something similar to Query-By-Example. For example, when browsing movies if the argument <tt>release_year</tt> is passed as &#8220;<tt>&gt;= 1969</tt>&#8220;, the results should only include films released on that year or later. This feature was not discussed in a post but had been <a href="https://github.com/jmafc/database-ui-tutorial/commit/851c875246699bb09b7c09618b6a0dbc473e5561">committed</a> to the tutorial repository.</p>
<h2>TTM and SQL</h2>
<p>The interface should follow the TTM guidelines when possible. For example, although implemented in Python, assignment to a relvar attribute defined as <tt>int</tt> should not be allowed if the value is of type <tt>str</tt>, and duplicate attribute names in a join expression should not be permitted. However, since the interface ought to be usable against existing SQL databases, allowance should be made for certain SQL features such as nullable attributes.</p>
<p>The implementation has been <a href="https://github.com/jmafc/Pyrseas/commit/08a0366ec90b494bdb76fbe92ab07d8082b99a28">committed</a> to the Pyrseas repository and changes were <a href="https://github.com/jmafc/database-ui-tutorial/commit/a2ef9627f9f37d081cb5b3267247d3f1cf0f7961">made</a> to the DBUI tutorial to use the new interface. Subsequent posts will cover the interface in more detail.</p>
<br />Filed under: <a href='http://pyrseas.wordpress.com/category/postgresql-2/'>PostgreSQL</a>, <a href='http://pyrseas.wordpress.com/category/python/'>Python</a>, <a href='http://pyrseas.wordpress.com/category/user-interfaces/'>User interfaces</a>  <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pyrseas.wordpress.com&#038;blog=19437126&#038;post=1597&#038;subd=pyrseas&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://pyrseas.wordpress.com/2013/03/07/a-pythonic-ttm-inspired-interface-to-postgresql-requirements/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0d235d4094b8dbf2cd9932667d828795?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jmafc</media:title>
		</media:content>

		<media:content url="http://www.assoc-amazon.com/e/ir?t=freedomcircle&#38;l=as2&#38;o=1&#38;a=1426937237" medium="image" />
	</item>
		<item>
		<title>A couple of Pyrseas enhancements</title>
		<link>http://pyrseas.wordpress.com/2013/01/21/a-couple-of-pyrseas-enhancements/</link>
		<comments>http://pyrseas.wordpress.com/2013/01/21/a-couple-of-pyrseas-enhancements/#comments</comments>
		<pubDate>Tue, 22 Jan 2013 04:59:04 +0000</pubDate>
		<dc:creator>jma</dc:creator>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Version control]]></category>
		<category><![CDATA[autodoc]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[version control]]></category>

		<guid isPermaLink="false">http://pyrseas.wordpress.com/?p=1894</guid>
		<description><![CDATA[Based on feedback from users and contributors, Pyrseas now sports two enhancements. Multi-line String Formatting Up to Pyrseas 0.6, long textual elements such as view definitions, function source text and long object comments, would usually be shown in the YAML &#8230; <a href="http://pyrseas.wordpress.com/2013/01/21/a-couple-of-pyrseas-enhancements/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pyrseas.wordpress.com&#038;blog=19437126&#038;post=1894&#038;subd=pyrseas&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Based on feedback from users and contributors, Pyrseas now sports two enhancements.</p>
<h2>Multi-line String Formatting</h2>
<p>Up to Pyrseas 0.6, long textual elements such as view definitions, function source text and long object comments, would usually be shown in the YAML output as quoted strings with embedded newlines. Here are two examples from the <a href="http://www.rbt.ca/autodoc/output.html">autodoc</a> database:</p>
<pre>schema product:
  description: "This schema stores a list of products and information\n about the\
    \ product"
...
schema warehouse:
  view products:
    definition: " SELECT DISTINCT product.product_id, product.product_code, product.product_description\n\
      \   FROM warehouse.inventory\n   JOIN product.product USING (product_id);"</pre>
<p>As you can imagine, this was particularly unsatisfactory for complex functions and views. Thanks to preliminary work by <a href="http://braintrace.ru/">Andrey Popp</a>, Pyrseas 0.7 will be able to format these elements in <a href="http://yaml.org/spec/1.1/current.html#block%20scalar%20style/syntax">YAML block style</a>. The above elements will be shown as follows:</p>
<pre>schema product:
  description: |-
    This schema stores a list of products and information
     about the product
...
schema warehouse:
  view products:
    definition: |2-
       SELECT DISTINCT product.product_id, product.product_code, product.product_description
         FROM warehouse.inventory
         JOIN product.product USING (product_id);</pre>
<p>Thanks to testing by Josep Martínez, 0.7 will also properly display and handle such strings even when they include non-ASCII characters such as accented characters. For example, in 0.6, &#8220;Martínez&#8221; would be shown as &#8220;Mart\xEDnez&#8221;. In 0.7, the output will be the original UTF-8 string.</p>
<h2>Directory of Database Objects</h2>
<p>Pyrseas 0.6 has a single format for output by <a href="http://pyrseas.readthedocs.org/en/latest/dbtoyaml.html">dbtoyaml</a> or input into <a href="http://pyrseas.readthedocs.org/en/latest/yamltodb.html">yamltodb</a>: a single YAML-formatted file. This becomes a problem when your database has hundreds or more tables, functions, etc (let alone <a href="https://www.pgcon.org/2011/schedule/attachments/193_pgCon%202011%20-%20Managing%20Terabytes.pdf">409,994 tables and counting!</a>). Furthermore, as dbtoyaml and yamltodb are intended to assist with database version control, your team may want to store individual object specifications in your version control system, or you may want to diff individual objects.</p>
<p>The 0.7 <tt>--directory</tt> option to dbtoyaml and yamltodb allows you to split the YAML spec into multiple files in a directory (or folder) tree. For example, using the dbtoyaml -d option on the autodoc database results in the following tree (shown under Linux using <tt>ls -RF</tt>):</p>
<pre>.:
schema.inherit/      schema.public/      schema.warehouse/
schema.inherit.yaml  schema.public.yaml  schema.warehouse.yaml
schema.product/      schema.store/
schema.product.yaml  schema.store.yaml

./schema.inherit:
table.tab1b.yaml  table.tab1.yaml  table.taba.yaml  table.tabb.yaml

./schema.product:
function.worker.yaml  sequence.product_product_id_seq.yaml  table.product.yaml

./schema.public:

./schema.store:
sequence.store_store_id_seq.yaml  table.inventory.yaml  table.store.yaml

./schema.warehouse:
function.worker.yaml                      table.warehouse.yaml
sequence.warehouse_warehouse_id_seq.yaml  view.products.yaml
table.inventory.yaml</pre>
<p>As can be seen, each schema gets its own directory wherein are stored each object belonging to that schema. In addition to schemas, the root level also stores non-schema owned objects such as foreign data wrappers and extensions (the latter can be placed in a schema, but are not owned by it).</p>
<p>The directory tree and multi-line string formats are still under review, so I&#8217;d like to encourage you to test both enhancements and <a href="https://github.com/jmafc/Pyrseas/issues">provide feedback</a>.</p>
<br />Filed under: <a href='http://pyrseas.wordpress.com/category/postgresql-2/'>PostgreSQL</a>, <a href='http://pyrseas.wordpress.com/category/python/'>Python</a>, <a href='http://pyrseas.wordpress.com/category/version-control/'>Version control</a>  <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pyrseas.wordpress.com&#038;blog=19437126&#038;post=1894&#038;subd=pyrseas&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://pyrseas.wordpress.com/2013/01/21/a-couple-of-pyrseas-enhancements/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0d235d4094b8dbf2cd9932667d828795?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jmafc</media:title>
		</media:content>
	</item>
		<item>
		<title>Testing Python and PostgreSQL on Windows, Part 6</title>
		<link>http://pyrseas.wordpress.com/2012/10/23/testing-python-and-postgresql-on-windows-part-6/</link>
		<comments>http://pyrseas.wordpress.com/2012/10/23/testing-python-and-postgresql-on-windows-part-6/#comments</comments>
		<pubDate>Tue, 23 Oct 2012 04:05:16 +0000</pubDate>
		<dc:creator>jma</dc:creator>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[collation]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[tox]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://pyrseas.wordpress.com/?p=1853</guid>
		<description><![CDATA[Alliterative locales, languages, collations. A tox on all your houses (test combinations). The last item to fix in the Pyrseas unit tests so that they run on Windows is related to the PostgreSQL 9.1 COLLATION feature. When creating the tests, &#8230; <a href="http://pyrseas.wordpress.com/2012/10/23/testing-python-and-postgresql-on-windows-part-6/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pyrseas.wordpress.com&#038;blog=19437126&#038;post=1853&#038;subd=pyrseas&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<blockquote><p>Alliterative locales, languages, collations.</p>
<p>A tox on all your houses (test combinations).</p></blockquote>
<p>The last item to fix in the Pyrseas unit tests so that they run on Windows is related to the PostgreSQL 9.1 <a href="http://www.postgresql.org/docs/9.1/static/collation.html">COLLATION</a> feature. When creating the tests, I was influenced by the examples in the documentation, i.e., I created a collation with &#8216;fr_FR.utf8&#8242; LC_COLLATE and LC_CTYPE. On Linux, it&#8217;s fairly straightforward to add such a locale to your system (although perhaps Windows users may disagree <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> ), so the tests worked as expected.</p>
<p>On Windows, however, most collation tests failed with</p>
<pre>DataError: could not create locale "fr_FR.utf8": No error</pre>
<p>Unfortunately, the PG documentation doesn&#8217;t seem to provide any hints on what is the Windows equivalent of &#8216;fr_FR.utf8&#8242; (or similar Linux locales). Eventually I figured it out by looking at the output of \l (list databases) in psql. This showed the Collation and Ctype (in my case) where &#8216;English_United States.1252&#8242; so I assumed what was needed was &#8216;French.France.1252&#8242;. Here is the procedure to set that up:</p>
<p><span style="color:#808080;">Open the Control Panel, select Date, Time, Language, and Regional Options, then Regional and Language Options (or Add other languages), click on the Advanced tab in the dialog and then choose &#8220;French (France)&#8221; from the dropdown. Finally, click OK and respond to any subsequent prompts to install the locale, including rebooting the machine.</span></p>
<p>Aside: For comparison, on Debian Linux, the equivalent procedure involves running <span style="color:#808080;">sudo dpkg-reconfigure locales</span>, selecting fr_FR.UTF-8 UTF-8 from a list, accepting the default locale and waiting for the locales to be generated (no reboot necessary). Second aside: On Linux, you can deselect a locale to remove it from your system, but Windows doesn&#8217;t appear to allow for language removals.</p>
<p>To test, make sure you have the latest <a href="https://github.com/jmafc/Pyrseas">Pyrseas code</a> from GitHub, which includes a change to fix the COLLATION tests to run on Windows.</p>
<p>Finally, we&#8217;re ready to install <a href="http://tox.testrun.org/latest/">Tox</a> and run all the unit tests with a single command. First, run <span style="color:#808080;">pip install tox</span> under both Python 2.7 and 3.2. Next, define (set) the environment variables PG84_PORT, PG90_PORT, PG91_PORT, and PG92_PORT to point to the corresponding PostgreSQL ports.</p>
<p>Then simply invoke tox from the Python 2.7 environment. Thanks to the Pyrseas tox.ini, this will install Python 2.7 and 3.2 virtualenvs, under a .tox subdirectory in the Pyrseas tree, install Psycopg2, PyYAML and Pyrseas into each virtualenv and run the unit tests eight times, once for each combination of Python and PostgreSQL.</p>
<p>If you have been following along, the only test failure should be in test_extension.py, in test_map_lang_extension, when attempting to CREATE EXTENSION plperl, due to the missing PERL514.DLL (see <a title="Testing Python and PostgreSQL on Windows, Part 5" href="http://pyrseas.wordpress.com/2012/10/17/testing-python-and-postgresql-on-windows-part-5/">previous post</a>). The error will only occur under PG 9.1 and 9.2.</p>
<p>The only problem I noticed with tox is that when there are errors it may get confused in its summary report.</p>
<pre>___________________________________ summary ___________________________________
  py27pg90: commands succeeded
  py27pg91: commands succeeded
  py27pg92: commands succeeded
ERROR:   py32pg91: commands failed
  py27pg84: commands succeeded
ERROR:   py32pg84: commands failed
ERROR:   py32pg90: commands failed
ERROR:   py32pg92: commands failed</pre>
<p>The errors actually occurred in the *pg91 and *pg92 environments but tox reports that all py32* tests failed, which was not the case. This is a minor issue considering all that tox accomplishes, with very little setup or configuration.</p>
<br />Filed under: <a href='http://pyrseas.wordpress.com/category/postgresql-2/'>PostgreSQL</a>, <a href='http://pyrseas.wordpress.com/category/python/'>Python</a>  <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pyrseas.wordpress.com&#038;blog=19437126&#038;post=1853&#038;subd=pyrseas&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://pyrseas.wordpress.com/2012/10/23/testing-python-and-postgresql-on-windows-part-6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0d235d4094b8dbf2cd9932667d828795?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jmafc</media:title>
		</media:content>
	</item>
		<item>
		<title>Testing Python and PostgreSQL on Windows, Part 5</title>
		<link>http://pyrseas.wordpress.com/2012/10/17/testing-python-and-postgresql-on-windows-part-5/</link>
		<comments>http://pyrseas.wordpress.com/2012/10/17/testing-python-and-postgresql-on-windows-part-5/#comments</comments>
		<pubDate>Wed, 17 Oct 2012 21:10:54 +0000</pubDate>
		<dc:creator>jma</dc:creator>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[dependency checking]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://pyrseas.wordpress.com/?p=1821</guid>
		<description><![CDATA[I&#8217;ve got the Perl on Windows blues &#8230; Aside from PL/pgSQL, the base distribution of PostgreSQL supports three procedural languages: Perl, Python and Tcl. When creating Pyrseas unit tests for languages (before they became EXTENSIONs), PL/Perl seemed like the &#8220;natural&#8221; &#8230; <a href="http://pyrseas.wordpress.com/2012/10/17/testing-python-and-postgresql-on-windows-part-5/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pyrseas.wordpress.com&#038;blog=19437126&#038;post=1821&#038;subd=pyrseas&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<blockquote><p>I&#8217;ve got the Perl on Windows blues &#8230;</p></blockquote>
<p>Aside from PL/pgSQL, the base distribution of PostgreSQL supports three procedural languages: Perl, Python and Tcl. When creating Pyrseas unit tests for languages (before they became EXTENSIONs), PL/Perl seemed like the &#8220;natural&#8221; choice. Perl is available on virtually all Linux and BSD base distributions, and (in contrast to Python) PL/Perl is available in both trusted and untrusted versions—a distinguishing attribute that the unit tests ought to check.</p>
<p>Alas, when testing on Windows I discovered that Perl isn&#8217;t as ubiquitous or as easy to deal with as it is on Linux.</p>
<p>The preliminary research prompted me to install Active Perl, specifically its <a href="http://www.activestate.com/activeperl/downloads">Community Edition</a>. Currently, the only two versions available are 5.14 and 5.16. Strangely enough, if you install one of those versions and then attempt to create the PL/Perl language under PG 8.4 or 9.0, the command succeeds, but when you try to create a function using plperl, you&#8217;ll see something like:</p>
<pre>ERROR:  could not load library "C:/Program Files/PostgreSQL/8.4/lib/plperl.dll":
 The specified module could not be found.</pre>
<p>Against PG 9.1 and 9.2, if you installed Perl 5.16, you&#8217;ll see the error message when issuing the CREATE EXTENSION (or LANGUAGE) statement. If you installed Perl 5.14, there should be no error.</p>
<p>When I first saw the error message, I was a bit puzzled since the plperl.dll libraries had all been installed and were located in the paths show in the messages. What &#8220;specified module&#8221; was missing?</p>
<p>Some web searching pointed me to <a href="http://www.dependencywalker.com/">Dependency Walker</a> (depends.exe), a tool that appears to be indispensable if you&#8217;re going to be testing with multiple executable and DLL versions. It is analogous to Linux <a href="https://en.wikipedia.org/wiki/Ldd_%28Unix%29">ldd</a>. Depends.exe showed that plperl.dll in the 8.4 and 9.0 installations was linked with PERL510.DLL and in 9.1 and 9.2 with PER514.DLL.</p>
<p>Unfortunately, Active Perl has no Perl 5.10 Community Edition available, so off I was looking for an alternative. Thus I found <a href="http://strawberryperl.com/">Strawberry Perl</a>.</p>
<p>The downside of Strawberry Perl&#8217;s installers is that they install it in C:\strawberry so you can&#8217;t have both Perl 5.10 and 5.14 at the same time. Someone on IRC explained that it <em>is</em> possible to install it in two separate paths (but it ain&#8217;t easy). For now, I chose to only install Perl 5.10. This allowed me to test Pyrseas using Python 2.7 and 3.2 against PostgreSQL 8.4, 9.0, 9.1 and 9.2, with only one Perl-related test faling (under PG 9.1 and 9.2, due to the absence of Perl 5.14).</p>
<p>A note of caution: Strawberry Perl installs GCC (3.4.5 in the Perl 5.10 version). If you have a pydistutils.cfg specifying a mingw32 compiler (as mentioned in my <a title="Testing Python and PostgreSQL on Windows, Part 3" href="http://pyrseas.wordpress.com/2012/09/28/testing-python-and-postgresql-on-windows-part-3/">previous post</a>), that may cause problems if you try to install or upgrade psycopg2 (or some other C extension module).</p>
<br />Filed under: <a href='http://pyrseas.wordpress.com/category/postgresql-2/'>PostgreSQL</a>, <a href='http://pyrseas.wordpress.com/category/python/'>Python</a>  <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pyrseas.wordpress.com&#038;blog=19437126&#038;post=1821&#038;subd=pyrseas&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://pyrseas.wordpress.com/2012/10/17/testing-python-and-postgresql-on-windows-part-5/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0d235d4094b8dbf2cd9932667d828795?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jmafc</media:title>
		</media:content>
	</item>
		<item>
		<title>Testing Python and PostgreSQL on Windows, Part 4</title>
		<link>http://pyrseas.wordpress.com/2012/10/03/testing-python-and-postgresql-on-windows-part-4/</link>
		<comments>http://pyrseas.wordpress.com/2012/10/03/testing-python-and-postgresql-on-windows-part-4/#comments</comments>
		<pubDate>Wed, 03 Oct 2012 21:47:41 +0000</pubDate>
		<dc:creator>jma</dc:creator>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[tablespaces]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://pyrseas.wordpress.com/?p=1738</guid>
		<description><![CDATA[At the end of Part 2, I suggested those who were anxious to start testing could try python tests\dbobject\test_schema.py right after installing psycopg2, and implied everything would work just fine by showing the output of a successful run. That was &#8230; <a href="http://pyrseas.wordpress.com/2012/10/03/testing-python-and-postgresql-on-windows-part-4/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pyrseas.wordpress.com&#038;blog=19437126&#038;post=1738&#038;subd=pyrseas&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>At the end of <a title="Testing Python and PostgreSQL on Windows, Part 2" href="http://pyrseas.wordpress.com/2012/09/25/testing-python-and-postgresql-on-windows-part-2/">Part 2</a>, I suggested those who were anxious to start testing could try <tt>python tests\dbobject\test_schema.py</tt> right after installing psycopg2, and implied everything would work just fine by showing the output of a successful run.</p>
<p>That was deceptive because before running the Pyrseas tests you need to create a PostgreSQL user. So you first need to connect using <tt>psql</tt> or <tt>pgAdmin</tt>, as the <tt>postgres</tt> user and issue a command such as the following:</p>
<pre>CREATE USER <em>username</em> CREATEDB SUPERUSER <em>password</em>;</pre>
<p>Of course, <em>username</em> and <em>password</em> should be your user name and a suitable password, respectively. While you&#8217;re at it, you can also create the two testing roles:</p>
<pre>CREATE ROLE user1;
CREATE ROLE user2;</pre>
<p>The user <em>username</em> needs the CREATEDB privilege to create the Pyrseas test database, by default, <tt>pyrseas_testdb</tt>. Alternatively, the test database could be created first, e.g., by <tt>postgres</tt> and owned by <em>username</em>. Also, if <em>username</em> isn&#8217;t granted the SUPERUSER privilege then the tests requiring it will be skipped.</p>
<p>One last detail before being able to run the tests: create a PostgreSQL <a href="http://www.postgresql.org/docs/current/static/libpq-pgpass.html">password file</a>, i.e., <tt>%APPDATA%\postgresql\pgpass.conf</tt>. The format is straightforward:</p>
<pre>*:*:*:<em>username</em>:<em>password</em></pre>
<p>Make sure you have the <a href="https://github.com/jmafc/Pyrseas/commit/7a74b94527dc842a60ff4cede3b55c5ed52f4a97">latest</a> <tt>pyrseas/testutils.py</tt>. It includes a change to make the tests portable to Windows. You&#8217;re now ready to give all the tests a whirl:</p>
<pre>python tests\dbobject\__init_py</pre>
<p>or you may prefer to use test discovery:</p>
<pre>python  -m unittest discover -s tests/dbobject</pre>
<p>One of the first issues you&#8217;ll notice is when running <tt>test_tablespace.py</tt>, which exercises support for PostgreSQL tablespaces. According to the <a href="http://www.postgresql.org/docs/current/static/manage-ag-tablespaces.html">documentation</a>, &#8220;tablespaces can be used <strong>only</strong> on systems that support symbolic links&#8221; (aside: thanks to Andres Freund and Merlin Moncure for answering questions about this on IRC).</p>
<p>It seems Windows Vista (or even XP) may have something akin to symbolic links (junctions?). Nevertheless for Pyrseas, it is sufficient to create directories for the tablespaces, e.g.,</p>
<pre>C:\&gt;md c:\somedir\pg\9.1\ts1
C:\&gt;md c:\somedir\pg\9.1\ts2</pre>
<p>However, when you try to define the tablespace from <tt>psql</tt>, you&#8217;ll probably see:</p>
<pre>postgres=# CREATE TABLESPACE ts1 LOCATION E'C:\\somedir\\pg\\9.1\\ts1';
ERROR:  could not set permissions on directory "C:/somedir/pg/9.1/ts1": Permission denied</pre>
<p>The problem is that the directory needs to be owned by the <tt>postgres</tt> user. Unfortunately, there is nothing equivalent to <tt>chown</tt> on native Windows XP Home. Andres had mentioned <tt>cacls</tt> and after some web searching and trying, I came up with the following commands as the nearest approximation to <tt>chown</tt>:</p>
<pre>cacls c:\somedir\pg\9.1\ts1 /E /G postgres:F
cacls c:\somedir\pg\9.1\ts2 /E /G postgres:F</pre>
<p>These give the <tt>postgres</tt> user FULL owner privileges over the directories. If you invoke the CREATE TABLESPACE statements again, then they should succeed &#8230; Well, at least on PostgreSQL 8.4, 9.0 and 9.1, the <tt>cacls</tt> commands allow the tablespaces to be defined. However, under 9.2 the &#8220;Permission denied&#8221; error persists (still haven&#8217;t figured out why—if you know why, do leave a comment).</p>
<p><strong>Update:</strong> Thank to alemarko&#8217;s comment below, I figured out that for PG 9.2, assuming you installed with the defaults, the correct incantations  to use are:</p>
<pre>cacls c:\somedir\pg\9.2\ts1 /E /G networkservice:F
cacls c:\somedir\pg\9.2\ts2 /E /G networkservice:F</pre>
<br />Filed under: <a href='http://pyrseas.wordpress.com/category/postgresql-2/'>PostgreSQL</a>, <a href='http://pyrseas.wordpress.com/category/python/'>Python</a>  <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pyrseas.wordpress.com&#038;blog=19437126&#038;post=1738&#038;subd=pyrseas&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://pyrseas.wordpress.com/2012/10/03/testing-python-and-postgresql-on-windows-part-4/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0d235d4094b8dbf2cd9932667d828795?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jmafc</media:title>
		</media:content>
	</item>
		<item>
		<title>Testing Python and PostgreSQL on Windows, Part 3</title>
		<link>http://pyrseas.wordpress.com/2012/09/28/testing-python-and-postgresql-on-windows-part-3/</link>
		<comments>http://pyrseas.wordpress.com/2012/09/28/testing-python-and-postgresql-on-windows-part-3/#comments</comments>
		<pubDate>Fri, 28 Sep 2012 04:05:03 +0000</pubDate>
		<dc:creator>jma</dc:creator>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[psycopg]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[tox]]></category>
		<category><![CDATA[virtualenv]]></category>

		<guid isPermaLink="false">http://pyrseas.wordpress.com/?p=1736</guid>
		<description><![CDATA[As a commenter mentioned in response to Part 2, an alternative to using pip install psycopg2, which requires that you first install VC++ 2008 Express, is to download and install the Windows port, aka win-psycopg. Jason Erickson makes these builds &#8230; <a href="http://pyrseas.wordpress.com/2012/09/28/testing-python-and-postgresql-on-windows-part-3/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pyrseas.wordpress.com&#038;blog=19437126&#038;post=1736&#038;subd=pyrseas&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>As a commenter mentioned in response to <a title="Testing Python and PostgreSQL on Windows, Part 2" href="http://pyrseas.wordpress.com/2012/09/25/testing-python-and-postgresql-on-windows-part-2/">Part 2</a>, an alternative to using <tt>pip install psycopg2</tt>, which requires that you first install VC++ 2008 Express, is to download and install the <a href="http://www.stickpeople.com/projects/python/win-psycopg/">Windows port</a>, aka win-psycopg. Jason Erickson makes these builds available for several versions of Python for both 32- and 64-bit Windows.</p>
<p>If you&#8217;re not planning to use <a href="http://pypi.python.org/pypi/virtualenv">virtualenv</a>s or <a href="http://tox.testrun.org/latest/">tox</a> (which creates virtualenvs for you), then the win-psycopg installer is the easiest way to satisfy the psycopg2 dependency (in fact, that&#8217;s how I started after the initial failure with pip). Simply download the Python 2.7 and 3.2 installers, run them and you&#8217;re done. However, the installers don&#8217;t work in a virtualenv (there is a workaround to extract the files, but I didn&#8217;t explore it because I wanted to use tox).</p>
<p>Another option is to build psycopg2 with the MinGW compiler. Daniele Varrazzo has a <a href="http://initd.org/psycopg/articles/2011/06/05/psycopg-windows-mingw/">post</a> describing this. Daniele used a special MinGW package, but I chose to install the latest (mingw-get-inst-20120426.exe) from <a href="http://mingw.org/">MinGW.org</a> (click on the Navigation &#8211; Downloads link which will take you to SourceForge).</p>
<p>To get the psycopg2 sources, you can <a href="http://initd.org/psycopg/download/">download the .tar.gz package</a>, or, since you have Git, do this from Git Bash:</p>
<pre>git clone git://luna.dndg.it/public/psycopg2.git
cd psycopg2
git checkout 2_4_5  # or latest tag</pre>
<p>Create a <tt>pydistutils.cfg</tt> file in your home directory (<tt>%USERPROFILE%</tt>) with the following (an alternative is to use the <tt>--compiler</tt> option to the <tt>python setup.py</tt> command below):</p>
<pre>[build]
compiler=mingw32</pre>
<p>Make sure MinGW, Python, and PostgreSQL are in your PATH, e.g., <tt>set PATH=C:\MinGW\bin;C:\Python27;C:\Program Files\PostgreSQL\8.4\bin;%PATH%<tt>, and then run:</tt></tt></p>
<pre>python setup.py build_ext build</pre>
<p>With the latest MinGW and unless <a href="http://bugs.python.org/issue12641">Python bug 12641</a> has been resolved, you&#8217;ll see the following error message:</p>
<pre>cc1.exe: error: unrecognized command line option '-mno-cygwin'</pre>
<p>The workaround is to edit the <tt>cygwincompiler.py</tt> file in your Python <tt>Lib\distutils</tt> directory and remove all instances of <tt>-mno-cygwin</tt>. Hopefully after that, the <tt>python setup.py</tt> above will work and then you can run the following to install it:</p>
<pre>python setup.py install</pre>
<p>Rinse and repeat for the Python 3.2 version and you should be ready to test connecting from both Python versions to PostgreSQL.</p>
<p><strong>Aside:</strong> To remove the pip-installed psycopg2, you run <tt>pip uninstall psycopg2</tt> from the corresponding Python environment. To remove win-psycopg, you use Control Panel&#8217;s Add or Remove Programs and click Remove on the desired version. To remove the versions installed with MinGW, I&#8217;m afraid you&#8217;ll have to resort to deleting the <tt>Lib\site-packages\psycopg2</tt> directories and the related <tt>psycopg2-*.egg-info</tt> files.</p>
<br />Filed under: <a href='http://pyrseas.wordpress.com/category/postgresql-2/'>PostgreSQL</a>, <a href='http://pyrseas.wordpress.com/category/python/'>Python</a>  <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pyrseas.wordpress.com&#038;blog=19437126&#038;post=1736&#038;subd=pyrseas&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://pyrseas.wordpress.com/2012/09/28/testing-python-and-postgresql-on-windows-part-3/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0d235d4094b8dbf2cd9932667d828795?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jmafc</media:title>
		</media:content>
	</item>
		<item>
		<title>Testing Python and PostgreSQL on Windows, Part 2</title>
		<link>http://pyrseas.wordpress.com/2012/09/25/testing-python-and-postgresql-on-windows-part-2/</link>
		<comments>http://pyrseas.wordpress.com/2012/09/25/testing-python-and-postgresql-on-windows-part-2/#comments</comments>
		<pubDate>Tue, 25 Sep 2012 19:31:26 +0000</pubDate>
		<dc:creator>jma</dc:creator>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[psycopg]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[pyyaml]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://pyrseas.wordpress.com/?p=1694</guid>
		<description><![CDATA[In the previous post, I covered installation of Git, PostgreSQL and Python under Windows in order to set up a Pyrseas testing and development environment. Today, we&#8217;ll explore installation of the Python dependencies. The Hitchhiker&#8217;s Guide to Python recommends first &#8230; <a href="http://pyrseas.wordpress.com/2012/09/25/testing-python-and-postgresql-on-windows-part-2/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pyrseas.wordpress.com&#038;blog=19437126&#038;post=1694&#038;subd=pyrseas&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>In the <a title="Testing Python and PostgreSQL on Windows – Basics" href="http://pyrseas.wordpress.com/2012/09/20/testing-python-and-postgresql-on-windows-basics/">previous post</a>, I covered installation of Git, PostgreSQL and Python under Windows in order to set up a Pyrseas testing and development environment. Today, we&#8217;ll explore installation of the Python dependencies.</p>
<p><a href="http://docs.python-guide.org/en/latest/starting/install/win/">The Hitchhiker&#8217;s Guide to Python</a> recommends first downloading and running the <a href="http://python-distribute.org/distribute_setup.py">distribute_setup.py</a> script. This gives you the <tt>easy_install</tt> command but the Guide recommends installing <a href="http://pypi.python.org/pypi/pip">pip</a> (with <tt>easy_install pip</tt>) and then using pip to install all other modules.</p>
<p>You can use pip to install pyyaml with the following command:</p>
<pre>pip install pyyaml</pre>
<p>However, if you try <tt>pip install psycopg2</tt> (or even <tt>easy_install psycopg2</tt>), it&#8217;s very likely you&#8217;ll see the error:</p>
<pre>error: Unable to find vcvarsall.bat</pre>
<p>As best as I&#8217;ve been able to determine the only way to get around this is by <a href="http://stackoverflow.com/questions/10407564/python-django-no-module-psycopg2-extension-even-after-installing-compiled-vers">installing Microsoft Visual Express Studio</a>. According to <a href="http://mail.python.org/pipermail/python-list/2010-April/573606.html">this email</a> and <a href="http://blog.victorjabur.com/tag/python-express-2010-visual-build-compile-windows-executable/">this post</a>, for Python 2.7, it <em>must be</em> the 2008 Express Studio which, to make things interesting, is no longer available from the download links given. If you search enough you may find it <a href="https://www.microsoft.com/en-us/download/details.aspx?displaylang=en&amp;id=14597">here</a> (download <tt>vcsetup.exe</tt>) (<strong>Update</strong> below). After installing VC++ 2008 Express (and if you haven&#8217;t installed Strawberry Perl—a later installment in our saga), the <tt>pip install psycopg2</tt> command should succeed.</p>
<p>However, if you try to <tt>import psycopg2</tt> at the Python 2.7 prompt you may be surprised with a traceback ending in:</p>
<pre>    from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: DLL load failed: The specified module could not be found.</pre>
<p>Ahh &#8230; the mysteries of Windows DLLs. Don&#8217;t despair: this probably means you don&#8217;t have the PostgreSQL DLLs (<tt>libpq.dll</tt> in particular) in your PATH. Add one of the <tt>postgres\x.x\bin</tt> directories to your PATH and (hopefully) you should then be able to connect from Python 2.7 to your PostgreSQL installations.</p>
<p>OK, let&#8217;s turn our attention to Python 3.2. If you followed the Hitchhiker&#8217;s Guide instructions previously and added <tt>C:\Python27</tt> to your PATH, you&#8217;ll now have to change that to <tt>C:\Python32</tt>. Suggestion: create a couple of batch scripts, e.g., <tt>env27.bat</tt> and <tt>env32.bat</tt>, so you can easily switch between the two Python installations. And don&#8217;t forget to add the <tt>postgres\x.x\bin</tt> directory as well.</p>
<p>For 3.2, once again run the <tt>distribute_setup.py</tt> script, <tt>easy_install pip</tt>, and <tt>pip install pyyaml</tt>, as for 2.7 above. Then you can run <tt>pip install psycopg2</tt>, and if you installed VC++ previously, the gods may smile upon you and you may see the following message:</p>
<pre>Successfully installed psycopg2
Cleaning up...</pre>
<p>At this point, if you followed along, you&#8217;ll have four versions of PostgreSQL (8.4 through 9.2), two versions of Python (2.7 and 3.2), each with PyYAML and psycopg2, ready for testing. If you&#8217;re anxious to check things out, invoke one of the PATH setup scripts and try the following, from the Pyrseas source directory:</p>
<pre>set PYTHONPATH=%USERPROFILE%\src\Pyrseas
C:\...\src\Pyrseas&gt;python tests\dbobject\test_schema.py
............
----------------------------------------------------------------------
Ran 12 tests in 1.452s

OK</pre>
<p>There are some alternatives to installing psycopg2 using pip and VC++ 2008.  I&#8217;ll cover those in a subsequent post.</p>
<p><strong>Update</strong>: Microsoft seems to keep changing download URLs. Your best bet is to search for &#8220;Visual C++ 2008 Express download.&#8221; Currently, that should lead you to the following <a href="http://go.microsoft.com/?linkid=7729279">download link</a>.</p>
<br />Filed under: <a href='http://pyrseas.wordpress.com/category/postgresql-2/'>PostgreSQL</a>, <a href='http://pyrseas.wordpress.com/category/python/'>Python</a>  <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pyrseas.wordpress.com&#038;blog=19437126&#038;post=1694&#038;subd=pyrseas&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://pyrseas.wordpress.com/2012/09/25/testing-python-and-postgresql-on-windows-part-2/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0d235d4094b8dbf2cd9932667d828795?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jmafc</media:title>
		</media:content>
	</item>
	</channel>
</rss>
