<?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/"
	>

<channel>
	<title>BigSmoke &#187; PostgreSQL</title>
	<atom:link href="http://blog.bigsmoke.us/tag/postgresql/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.bigsmoke.us</link>
	<description>Smokes your problems, coughs fresh air.</description>
	<lastBuildDate>Wed, 08 Sep 2010 14:31:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Some new (upcoming) PostgreSQL features</title>
		<link>http://blog.bigsmoke.us/2009/04/15/some-new-postgresql-features</link>
		<comments>http://blog.bigsmoke.us/2009/04/15/some-new-postgresql-features#comments</comments>
		<pubDate>Wed, 15 Apr 2009 20:20:54 +0000</pubDate>
		<dc:creator>Rowan Rodrik</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://blog.bigsmoke.us/?p=475</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p>These are some random new PostgreSQL features that I&#8217;m interested in:</p>

<ul>
<li>
<p>The 
<a href="http://okbob.blogspot.com/2008/06/execute-using-feature-in-postgresql-84.html">EXECUTE USING feature in PostgreSQL 8.4</a> will allow the use of more secure dynamic SQL in PL/PgSQL.</p>
</li>

<li>
<p><a href="http://developer.postgresql.org/pgdocs/postgres/plpgsql-errors-and-messages.html">User defined exceptions in PostgreSQL 8.4</a> are a very exciting feature to me. In our <a href="http://www.bigsmoke.us/postgresql-unit-testing/">unit tests</a> we often check if an exception is properly raised. However, for exception that we raise ourselves, we&#8217;ve never been able to check <em>which</em> exception is raised.</p>
<p>Another exciting possibility is that this will allow us to come up with a very clean validation scheme that produces exceptions that we&#8217;ll be able to use in the client web GUI.</p>
</li>

<li>
<p><a href="http://developer.postgresql.org/pgdocs/postgres/sql-select.html#SQL-WITH">WITH queries in PostgreSQL 8.4</a> will allow some <a href="http://www.depesz.com/index.php/2008/10/07/waiting-for-84-common-table-expressions-with-queries/">very cool things</a>, the coolest of which is something that I&#8217;ve wished for on more than one occasion: <em>recursion</em>.</p>
</li>

<li>
<p>The introduction of proper support for the <a href="http://www.postgresql.org/docs/current/static/datatype-xml.html">SQL standard XML Type</a> makes me wish that my <a href="http://www.nearlyfreespeech.net/">favorite web hosting provider</a> would support a <a href="http://www.postgresql.org/">real database</a> besides their standard MySQL offering.</p>
</li>

<li>
<p><a href="http://www.postgresql.org/docs/current/static/datatype-enum.html">Enumerated Types</a> will make some of my table definitions slightly clearer.</p>
<pre class="sql"><span style="color: #808080; font-style: italic;">-- This isn't too shabby (thanks to the CHECK constraint):</span>
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> persons <span style="color: #66cc66;">&#40;</span>
the_gender CHAR<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">CHECK</span> <span style="color: #66cc66;">&#40;</span>gender = <span style="color: #ff0000;">'m'</span> <span style="color: #993333; font-weight: bold;">OR</span> gender = <span style="color: #ff0000;">'f'</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">-- But, I like this much better:</span>
<span style="color: #993333; font-weight: bold;">CREATE</span> TYPE gender <span style="color: #993333; font-weight: bold;">AS</span> ENUM <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'male'</span>, <span style="color: #ff0000;">'female'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> persons <span style="color: #66cc66;">&#40;</span>
the_gender gender
<span style="color: #66cc66;">&#41;</span>;</pre>
</li>

</ul>

<p>Extra kudos to the PostgreSQL development team for their accelerating pace! <img src='http://blog.bigsmoke.us/wp-factory/wp-includes/images/smilies/icon_biggrin.gif' alt=':-D' class='wp-smiley' /> </p>]]></content:encoded>
			<wfw:commentRss>http://blog.bigsmoke.us/2009/04/15/some-new-postgresql-features/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PostgreSQL back-end for Ruby on Rails confusion</title>
		<link>http://blog.bigsmoke.us/2008/08/28/postgresql-back-end-for-ruby-on-rails-confusion</link>
		<comments>http://blog.bigsmoke.us/2008/08/28/postgresql-back-end-for-ruby-on-rails-confusion#comments</comments>
		<pubDate>Thu, 28 Aug 2008 14:02:09 +0000</pubDate>
		<dc:creator>halfgaar</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[postgres]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://blog.bigsmoke.us/?p=148</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p>
I just need to add a quick summary of what postgres back-end tool our Ruby on Rails application uses, and how we&#8217;ve configured it, because it&#8217;s quite confusing&#8230;
</p>

<p>
There are four postgresql backends:
</p>

<ul>
<li>ruby-postgres. This version is no longer maintained. This is the version we used when the project began.</li>
<li>postgres-pr. This is a pure ruby implementation, which is not interesting for us.</li>
<li>postgres. This is the continuation of the unmaintained ruby-postgres. This version includes such fixes as that it can be compiled against libpg-8.3.</li>
<li>ruby-pg. It is said that this one is <a href="http://people.planetpostgresql.org/jdavis/index.php?/archives/5-ruby-pg-is-now-the-official-postgres-ruby-gem.html">now the official postgres back-end</a>, but when I install it, the application still can&#8217;t find &#8220;postgres&#8221;.</li>
</ul>

<p>
Because the aforementioned article states that the pg extension is unstable, &#8220;postgres&#8221; seems to be what we should use. The article states that it is included in the ruby-pg package, but it doesn&#8217;t work when I install it, so I had to install &#8220;postgres&#8221;. I uninstalled ruby-pg, because it doesn&#8217;t seem necessary.
</p>

<p>
To continue, we once used a patched postgresql adapter, because we needed more accurate timestamps (the standard connection adapter rounded everything off to whole seconds), but if I recall correctly, this patch was only necessary on the connection adapter in Rails, not the back-end. We never commissioned the functionality that required this, so this existed only in the workdir of one of the devs.
</p>

<p>
As a final note; on our production server, we have a version of ruby-postgres installed in /usr/local. I can&#8217;t remember why&#8230;
</p>]]></content:encoded>
			<wfw:commentRss>http://blog.bigsmoke.us/2008/08/28/postgresql-back-end-for-ruby-on-rails-confusion/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Native PostgreSQL authentication in Rails with rails-psql-auth</title>
		<link>http://blog.bigsmoke.us/2007/07/16/rails-psql-auth</link>
		<comments>http://blog.bigsmoke.us/2007/07/16/rails-psql-auth#comments</comments>
		<pubDate>Mon, 16 Jul 2007 13:58:13 +0000</pubDate>
		<dc:creator>Rowan Rodrik</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[HTTP]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://blog.bigsmoke.us/2007/07/16/rails-psql-auth</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p>A while ago, I wrote a <a href="http://rubyforge.org/projects/rails-psql-auth/">PostgreSQL auth</a> plugin for <a href="http://www.rubyonrails.org/">Rails</a>. The plugin basically defers all authentication and authorization worries to the database layer where they are supposed to be taken care of anyway.</p>

<p>Using this plugin, the user is asked for his or her credentials using a HTTP Basic authentication challenge. (The code for this is adapted from <a href="http://www.codahale.com/">Coda Hale</a>&#8216;s <a href="http://blog.codahale.com/2006/05/11/basic-http-authentication-with-rails-simple_http_auth/">Basic HTTP authentication plugin</a>.) It&#8217;s possible to specify a <tt>guest_username</tt> in the <tt>database.yml</tt> which will be used as a fall-back if no credentials are supplied. After successful login or if a guest user is found, the plugin will make sure that all database operations run as that user. If any operation fails due to insufficient user rights, the user will be prompted for a username/password pair again.</p>

<p>Detailed and up-to-date documentation for the plugin can always be found at the plugin&#8217;s <a href="http://rails-psql-auth.rubyforge.org/">homepage</a>. Go to the plugin&#8217;s <a href="http://rubyforge.org/projects/rails-psql-auth/">project page</a> for getting help or for reporting issues with the plugin.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.bigsmoke.us/2007/07/16/rails-psql-auth/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unique constraints and indexes in PostgreSQL</title>
		<link>http://blog.bigsmoke.us/2007/02/02/postgresql-unique-constraints-and-indexes</link>
		<comments>http://blog.bigsmoke.us/2007/02/02/postgresql-unique-constraints-and-indexes#comments</comments>
		<pubDate>Fri, 02 Feb 2007 22:11:29 +0000</pubDate>
		<dc:creator>Rowan Rodrik</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[DB]]></category>
		<category><![CDATA[pgAdmin]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Sicirec]]></category>

		<guid isPermaLink="false">http://blog.bigsmoke.us/2007/02/02/postgresql-unique-contraints-and-indexes</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p>This afternoon, I had to add a unique index for some table in the Sicirec <a href="http://www.postgresql.org/">PostgreSQL</a> database. I had already assumed that I needed to use <tt>CREATE UNIQUE INDEX</tt> to create my new unique index until I noticed, thanks to <a href="http://www.pgadmin.org/">pgAdmin</a>&#8216;s clear GUI, that some tables clearly had unique constraints <em>and</em> unique indexes while one table lacked a unique <em>constraint</em> and only had an unique index defined.</p>

<p>This motivated me to take a closer look at PostgreSQL&#8217;s documentation <a href="http://www.postgresql.org/docs/8.1/interactive/indexes-unique.html">on unique indexes</a>:</p>

<blockquote cite="http://www.postgresql.org/docs/8.1/interactive/indexes-unique.html">
<p><b>Note: </b> The preferred way to add a unique constraint to a table is <tt class="literal">ALTER TABLE ... ADD CONSTRAINT</tt>.  The use of indexes to enforce unique constraints could be considered an implementation detail that should not be accessed directly.  One should, however, be aware that there&#8217;s no need to manually create indexes on unique columns; doing so would just duplicate the automatically-created index.</p>
</blockquote>

<p>Grepping for <q><tt>CREATE UNIQUE INDEX</tt></q> in our migration history quickly revealed that the index which lacked an accompanying constraint was indeed created by <tt>CREATE UNIQUE INDEX</tt> instead of by <tt>ALTER TABLE ... ADD CONSTRAINT</tt>. So,  now I know that, indeed, I have to use <tt class="literal">ALTER TABLE ... ADD CONSTRAINT</tt> instead of <tt>CREATE UNIQUE INDEX</tt> to add unique constraints with accompanying indexes to existing tables.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.bigsmoke.us/2007/02/02/postgresql-unique-constraints-and-indexes/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
