<?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>Pasha Golub&#039;s Blog &#187; PostgreSQL</title>
	<atom:link href="http://pgolub.wordpress.com/category/postgresql/feed/" rel="self" type="application/rss+xml" />
	<link>http://pgolub.wordpress.com</link>
	<description>Nullus est in vitae sensus, ipsa vera est sensus</description>
	<lastBuildDate>Tue, 14 May 2013 13:05:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='pgolub.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://1.gravatar.com/blavatar/b5ec0b5169e018796e786f9e8ada4617?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>Pasha Golub&#039;s Blog &#187; PostgreSQL</title>
		<link>http://pgolub.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://pgolub.wordpress.com/osd.xml" title="Pasha Golub&#039;s Blog" />
	<atom:link rel='hub' href='http://pgolub.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Development using Lazarus and PostgresDAC. Installation</title>
		<link>http://pgolub.wordpress.com/2013/04/19/postgresql-development-using-lazarus-and-postgresdac/</link>
		<comments>http://pgolub.wordpress.com/2013/04/19/postgresql-development-using-lazarus-and-postgresdac/#comments</comments>
		<pubDate>Fri, 19 Apr 2013 14:41:02 +0000</pubDate>
		<dc:creator>pashagolub</dc:creator>
				<category><![CDATA[PostgresDAC]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[FreePascal]]></category>
		<category><![CDATA[lazarus]]></category>
		<category><![CDATA[PostgreSQL]]></category>

		<guid isPermaLink="false">http://pgolub.wordpress.com/?p=1843</guid>
		<description><![CDATA[Preface There are a lot of tools for PostgreSQL development. I want to propose you one more. Why Lazarus: Lazarus is shipped with open-source Pascal compiler; it has a high degree of Delphi compatibility; availability on a variety of platforms,<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://pgolub.wordpress.com/2013/04/19/postgresql-development-using-lazarus-and-postgresdac/">Read more &#8250;</a></div><!-- end of .read-more --><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pgolub.wordpress.com&#038;blog=5816673&#038;post=1843&#038;subd=pgolub&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<h3>Preface</h3>
<p>There are a lot of tools for PostgreSQL development. I want to propose you one more. Why <a href="http://www.lazarus.freepascal.org/">Lazarus</a>:</p>
<ul>
<li>Lazarus is shipped with open-source Pascal compiler;</li>
<li>it has a high degree of Delphi compatibility;</li>
<li>availability on a variety of platforms, including Windows, Mac OS X, and Linux;</li>
<li>complete source code is available;</li>
</ul>
<h3>Installing Lazarus</h3>
<p>Go to <a href="http://sourceforge.net/projects/lazarus/">Lazarus at SourceForge</a>.</p>
<p>Then at the <a href="http://sourceforge.net/projects/lazarus/files/">Downloads Section</a> get proper installer. I used lazarus-1.0.8-fpc-2.6.2-win32.exe and lazarus-1.0.8-fpc-2.6.2-win64.exe in my tests. These are the latest releases at the moment.</p>
<p>Here are the screen shots of the installation process where you can see what I had chosen:<br />
<a href="http://pgolub.files.wordpress.com/2013/04/clipboard014.jpg"><img class="aligncenter size-full wp-image-1844" alt="Lazarus Installation" src="http://pgolub.files.wordpress.com/2013/04/clipboard014.jpg?w=605"   /></a></p>
<p><a href="http://pgolub.files.wordpress.com/2013/04/clipboard03.jpg"><img class="aligncenter size-full wp-image-1845" alt="Path to install" src="http://pgolub.files.wordpress.com/2013/04/clipboard03.jpg?w=605"   /></a></p>
<p><a href="http://pgolub.files.wordpress.com/2013/04/clipboard04.jpg"><img class="aligncenter size-full wp-image-1846" alt="Full installation" src="http://pgolub.files.wordpress.com/2013/04/clipboard04.jpg?w=605"   /></a></p>
<p>I have Lazarus installed into <strong>C:\lazarus\</strong> and hereafter I will use this path.</p>
<h3>Getting PostgresDAC</h3>
<p>Now it&#8217;s time for <a href="http://microolap.com/products/connectivity/postgresdac/">PostgresDAC</a>. At the moment many Laarus IDE functions require the source and warns if the source of a unit is missing. Thus we need PostgresDAC with sources version. Sources are available for licensed users in their profile.</p>
<p><a href="http://pgolub.files.wordpress.com/2013/04/clipboard05.jpg"><img src="http://pgolub.files.wordpress.com/2013/04/clipboard05.jpg?w=605&#038;h=202" alt="MicroOLAP Profile" width="605" height="202" class="aligncenter size-large wp-image-1847" /></a></p>
<p>I have extracted PostgresDAC sources to <strong>C:\PostgresDAC\</strong>.</p>
<h3>Install PostgresDAC into the IDE</h3>
<p>In the Lazarus IDE choose open package and select <strong>dclPostgresDACL.lpk</strong>. This is the design time package. Then in the Package window choose <strong>Use → Install</strong>.<br />
<a href="http://pgolub.files.wordpress.com/2013/04/clipboard06.jpg"><img src="http://pgolub.files.wordpress.com/2013/04/clipboard06.jpg?w=605&#038;h=416" alt="Install package" width="605" height="416" class="aligncenter size-large wp-image-1848" /></a></p>
<p>Confirmation about rebuild will appear.</p>
<p><a href="http://pgolub.files.wordpress.com/2013/04/clipboard07.jpg"><img src="http://pgolub.files.wordpress.com/2013/04/clipboard07.jpg?w=605&#038;h=418" alt="Rebuild?" width="605" height="418" class="aligncenter size-large wp-image-1849" /></a></p>
<p>Choose &#8220;Yes&#8221;. Wait for some time. After successful rebuild Lazarus will reopen itself. Tada! We got it!</p>
<p><a href="http://pgolub.files.wordpress.com/2013/04/clipboard08.jpg"><img src="http://pgolub.files.wordpress.com/2013/04/clipboard08.jpg?w=605&#038;h=276" alt="PostgresDAC in the Lazarus" width="605" height="276" class="aligncenter size-large wp-image-1850" /></a></p>
<p>Now we may open some demo projects and play some time.<br />
<a href="http://pgolub.files.wordpress.com/2013/04/clipboard09.jpg"><img src="http://pgolub.files.wordpress.com/2013/04/clipboard09.jpg?w=605&#038;h=427" alt="GridDemo for PostgresDAC in the Lazarus" width="605" height="427" class="aligncenter size-large wp-image-1851" /></a></p>
<br />Filed under: <a href='http://pgolub.wordpress.com/category/postgresql/postgresdac/'>PostgresDAC</a> Tagged: <a href='http://pgolub.wordpress.com/tag/development/'>development</a>, <a href='http://pgolub.wordpress.com/tag/freepascal/'>FreePascal</a>, <a href='http://pgolub.wordpress.com/tag/lazarus/'>lazarus</a>, <a href='http://pgolub.wordpress.com/tag/postgresdac/'>PostgresDAC</a>, <a href='http://pgolub.wordpress.com/tag/postgresql/'>PostgreSQL</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pgolub.wordpress.com&#038;blog=5816673&#038;post=1843&#038;subd=pgolub&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://pgolub.wordpress.com/2013/04/19/postgresql-development-using-lazarus-and-postgresdac/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/24a7da587040285b6213974ed8933fdf?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">pashagolub</media:title>
		</media:content>

		<media:content url="http://pgolub.files.wordpress.com/2013/04/clipboard014.jpg" medium="image">
			<media:title type="html">Lazarus Installation</media:title>
		</media:content>

		<media:content url="http://pgolub.files.wordpress.com/2013/04/clipboard03.jpg" medium="image">
			<media:title type="html">Path to install</media:title>
		</media:content>

		<media:content url="http://pgolub.files.wordpress.com/2013/04/clipboard04.jpg" medium="image">
			<media:title type="html">Full installation</media:title>
		</media:content>

		<media:content url="http://pgolub.files.wordpress.com/2013/04/clipboard05.jpg?w=605" medium="image">
			<media:title type="html">MicroOLAP Profile</media:title>
		</media:content>

		<media:content url="http://pgolub.files.wordpress.com/2013/04/clipboard06.jpg?w=605" medium="image">
			<media:title type="html">Install package</media:title>
		</media:content>

		<media:content url="http://pgolub.files.wordpress.com/2013/04/clipboard07.jpg?w=605" medium="image">
			<media:title type="html">Rebuild?</media:title>
		</media:content>

		<media:content url="http://pgolub.files.wordpress.com/2013/04/clipboard08.jpg?w=605" medium="image">
			<media:title type="html">PostgresDAC in the Lazarus</media:title>
		</media:content>

		<media:content url="http://pgolub.files.wordpress.com/2013/04/clipboard09.jpg?w=605" medium="image">
			<media:title type="html">GridDemo for PostgresDAC in the Lazarus</media:title>
		</media:content>
	</item>
		<item>
		<title>Do we need LIMIT clause in UPDATE and DELETE statements for PostgreSQL?</title>
		<link>http://pgolub.wordpress.com/2012/11/23/do-we-need-limit-clause-in-update-and-delete-statements-for-postgresql/</link>
		<comments>http://pgolub.wordpress.com/2012/11/23/do-we-need-limit-clause-in-update-and-delete-statements-for-postgresql/#comments</comments>
		<pubDate>Fri, 23 Nov 2012 13:47:09 +0000</pubDate>
		<dc:creator>pashagolub</dc:creator>
				<category><![CDATA[Polls]]></category>
		<category><![CDATA[PostgreSQL]]></category>

		<guid isPermaLink="false">http://pgolub.wordpress.com/?p=1825</guid>
		<description><![CDATA[Was working with MySQL recently. Noticed that UPDATE command of it has special LIMIT clause which is really useful as for me, e.g. UPDATE `Product_download` SET `version`='9.2.1' WHERE `product_download_id`=367 LIMIT 1; Filed under: Polls, PostgreSQL<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pgolub.wordpress.com&#038;blog=5816673&#038;post=1825&#038;subd=pgolub&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Was working with MySQL recently. Noticed that <strong>UPDATE</strong> command of it has special <strong>LIMIT</strong> clause which is really useful as for me, e.g.</p>
<blockquote><p><code>UPDATE `Product_download` SET `version`='9.2.1' WHERE `product_download_id`=367 LIMIT 1;</code></p></blockquote>
<div align="center">
<a name="pd_a_6713113"></a>
<div class="PDS_Poll" id="PDI_container6713113" data-settings="{&quot;url&quot;:&quot;http:\/\/static.polldaddy.com\/p\/6713113.js&quot;}" style="display:inline-block;"></div>
<div id="PD_superContainer"></div>
<noscript><a href="http://polldaddy.com/poll/6713113">Take Our Poll</a></noscript>
</div>
<br />Filed under: <a href='http://pgolub.wordpress.com/category/polls/'>Polls</a>, <a href='http://pgolub.wordpress.com/category/postgresql/'>PostgreSQL</a>  <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pgolub.wordpress.com&#038;blog=5816673&#038;post=1825&#038;subd=pgolub&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://pgolub.wordpress.com/2012/11/23/do-we-need-limit-clause-in-update-and-delete-statements-for-postgresql/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/24a7da587040285b6213974ed8933fdf?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">pashagolub</media:title>
		</media:content>
	</item>
		<item>
		<title>Number into words convertion in PostgreSQL</title>
		<link>http://pgolub.wordpress.com/2012/11/16/number-into-words-convertion-in-postgresql/</link>
		<comments>http://pgolub.wordpress.com/2012/11/16/number-into-words-convertion-in-postgresql/#comments</comments>
		<pubDate>Fri, 16 Nov 2012 10:42:59 +0000</pubDate>
		<dc:creator>pashagolub</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[PostgresDAC]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[trick]]></category>

		<guid isPermaLink="false">http://pgolub.wordpress.com/?p=1803</guid>
		<description><![CDATA[I was playing with some unit tests for PostgresDAC recently. And one test case was to check TPSQLDataset.Locate routine which allows partial-string and case-sensitive matching options. So I want to have some test result set with integer and text columns.<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://pgolub.wordpress.com/2012/11/16/number-into-words-convertion-in-postgresql/">Read more &#8250;</a></div><!-- end of .read-more --><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pgolub.wordpress.com&#038;blog=5816673&#038;post=1803&#038;subd=pgolub&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I was playing with some unit tests for <a href="http://microolap.com/products/connectivity/postgresdac/">PostgresDAC</a> recently. And one test case was to check <a href="http://microolap.com/products/connectivity/postgresdac/help/TPSQLDataset/Methods/Locate.htm">TPSQLDataset.Locate</a> routine which allows partial-string and case-sensitive matching options. So I want to have some test result set with integer and text columns. The simplest for me are numbers in both representations: using digits and using words, e.g.</p>
<ol>
<li>one</li>
<li>two</li>
<li>three</li>
<li>four</li>
<li>etc.</li>
</ol>
<p>Since I hadn&#8217;t much spare time I used nice <a href="http://www.postgresql.org/docs/9.2/static/sql-values.html">VALUES</a> command:</p>
<table style="border-collapse:collapse;margin-top:15px;margin-bottom:15px;" border="0" cellspacing="0" cellpadding="5" bgcolor="LightYellow">
<tbody>
<tr>
<td>
<pre>
<strong>VALUES </strong>(1, <em>'one'</em>), (2, <em>'two'</em>), (3, <em>'three'</em>);
</pre>
</td>
</tr>
</tbody>
</table>
<p>Considering I needed special names for columns I used more complex query:</p>
<table style="border-collapse:collapse;margin-top:15px;margin-bottom:15px;" border="0" cellspacing="0" cellpadding="5" bgcolor="LightYellow">
<tbody>
<tr>
<td>
<pre>
<strong>SELECT </strong>col1, col2::varchar(10) <strong>FROM </strong>
(<strong>VALUES </strong>(1, <em>'one'</em>), (2, <em>'two'</em>), (3, <em>'three'</em>)) <strong>AS</strong> t(col1, col2);
</pre>
</td>
</tr>
</tbody>
</table>
<p>I did my task well. However I was wondering is there any built-in function in PostgreSQL which may convert integer to such words representation. The answer is: not exactly. </p>
<p>I found some references to <strong>cash_words</strong> function. But there is no any information (except entry in <a href="http://www.postgresql.org/docs/9.2/static/release-7-3.html">7.3 release notes</a>) in the official documents. The use case is quite simple:</p>
<table style="border-collapse:collapse;margin-top:15px;margin-bottom:15px;" border="0" cellspacing="0" cellpadding="5" bgcolor="LightYellow">
<tbody>
<tr>
<td>
<pre>
<strong>SELECT</strong> cash_words(gen.i::money) <strong>FROM </strong>generate_series(1, 10) <strong>AS</strong> gen(i);
</pre>
</td>
</tr>
<tr>
<td>
<pre>
cash_words <strong>text</strong>
<hr />
"One dollar and zero cents"
"Two dollars and zero cents"
"Three dollars and zero cents"
"Four dollars and zero cents"
"Five dollars and zero cents"
"Six dollars and zero cents"
"Seven dollars and zero cents"
"Eight dollars and zero cents"
"Nine dollars and zero cents"
"Ten dollars and zero cents"
</pre>
</td>
</tr>
</tbody>
</table>
<p>I&#8217;m fine with this result set, who needs only numbers may trim values using standard functions.</p>
<p>PS In case someone wants to create his own implementation using C (or plpgsql, who knows), <em>cash_words</em> function may be found in the <em>\src\backend\utils\adt\cash.c</em> file. It uses <em>num_word</em> private routine.</p>
<br />Filed under: <a href='http://pgolub.wordpress.com/category/postgresql/coding/'>Coding</a>, <a href='http://pgolub.wordpress.com/category/postgresql/postgresdac/'>PostgresDAC</a> Tagged: <a href='http://pgolub.wordpress.com/tag/postgresdac/'>PostgresDAC</a>, <a href='http://pgolub.wordpress.com/tag/postgresql/'>PostgreSQL</a>, <a href='http://pgolub.wordpress.com/tag/trick/'>trick</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pgolub.wordpress.com&#038;blog=5816673&#038;post=1803&#038;subd=pgolub&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://pgolub.wordpress.com/2012/11/16/number-into-words-convertion-in-postgresql/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/24a7da587040285b6213974ed8933fdf?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">pashagolub</media:title>
		</media:content>
	</item>
		<item>
		<title>PGConf.EU 2012: My schedule</title>
		<link>http://pgolub.wordpress.com/2012/10/02/pgconf-eu-2012-my-schedule/</link>
		<comments>http://pgolub.wordpress.com/2012/10/02/pgconf-eu-2012-my-schedule/#comments</comments>
		<pubDate>Tue, 02 Oct 2012 09:27:23 +0000</pubDate>
		<dc:creator>pashagolub</dc:creator>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[pgconf.eu]]></category>

		<guid isPermaLink="false">http://pgolub.wordpress.com/?p=1795</guid>
		<description><![CDATA[Well, I suppose it&#8217;s time to choose the most interesting talks to visit at PGConf.EU 2012. I sketched out a rough list. Wednesday, October 24 11:10 - 12:00 Writing a foreign data wrapper Bernd Helmle 12:10 - 13:00 MultiMaster Replication:<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://pgolub.wordpress.com/2012/10/02/pgconf-eu-2012-my-schedule/">Read more &#8250;</a></div><!-- end of .read-more --><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pgolub.wordpress.com&#038;blog=5816673&#038;post=1795&#038;subd=pgolub&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><a href="http://2012.pgconf.eu/"><img class="alignright" title="PGConf.EU" src="http://2012.pgconf.eu/files/img/logo.png" alt="PGConf.EU" width="100" height="103" /></a>Well, I suppose it&#8217;s time to choose the most interesting <a href="http://www.postgresql.eu/events/schedule/pgconfeu2012/">talks</a> to visit at <a href="http://2012.pgconf.eu/">PGConf.EU 2012</a>. I sketched out a rough list.</p>
<p><strong>Wednesday, October 24</strong></p>
<p><code> 11:10 - 12:00<br />
Writing a foreign data wrapper<br />
Bernd Helmle</code></p>
<p><code> 12:10 - 13:00<br />
MultiMaster Replication: Applications, Comparison, Implementation<br />
Andres Freund, Simon Riggs<br />
</code></p>
<p><code> 14:00 - 14:50<br />
Understanding EXPLAIN's output<br />
Guillaume Lelarge</code></p>
<p><code> 15:20 - 16:10<br />
Range Types in PostgreSQL 9.2 - Your Life Will Never Be The Same<br />
Jonathan S. Katz</code></p>
<p><code> 16:20 - 17:10<br />
CREATE EXTENSION pgchess;<br />
Gianni Ciolli</code></p>
<p><strong>Thursday, October 25</strong></p>
<p><code> 09:30 - 10:20<br />
Graphs and topology with PostgreSQL and PostGIS<br />
Vincent Picavet</code></p>
<p><code> 10:50 - 11:40<br />
Universal Data Access with SQL/MED<br />
David Fetter</code></p>
<p><code> 11:50 - 12:40<br />
Elephants and Windmills<br />
Josh Berkus </code></p>
<p><code> 13:40 - 14:30<br />
Inside PostgreSQL Shared Memory<br />
Bruce Momjian</code></p>
<p><code> 14:40 - 15:30<br />
Embracing the Web with JSON and PLV8<br />
Will Leinweber</code></p>
<p><strong>Friday, October 26</strong></p>
<p><code> 09:30 - 10:20<br />
PostBIS - A Bioinformatics Booster for PostgreSQL<br />
Michael Schneider </code></p>
<p><code> 10:50 - 11:40<br />
PostgreSQL makes dev happy, a pgAgent + pl/pgsql use case<br />
Julien Rouhaud</code></p>
<p><code> 11:50 - 12:40<br />
Debugging complex SQL queries with writable CTEs<br />
Gianni Ciolli</code></p>
<p><code> 13:40 - 14:30<br />
Using PostgreSQL for storing time-series data<br />
Sebastian Harl</code></p>
<p>Meet me at the PGConf.EU soon!</p>
<br />Filed under: <a href='http://pgolub.wordpress.com/category/postgresql/'>PostgreSQL</a> Tagged: <a href='http://pgolub.wordpress.com/tag/pgconf-eu/'>pgconf.eu</a>, <a href='http://pgolub.wordpress.com/tag/postgresql/'>PostgreSQL</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pgolub.wordpress.com&#038;blog=5816673&#038;post=1795&#038;subd=pgolub&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://pgolub.wordpress.com/2012/10/02/pgconf-eu-2012-my-schedule/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/24a7da587040285b6213974ed8933fdf?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">pashagolub</media:title>
		</media:content>

		<media:content url="http://2012.pgconf.eu/files/img/logo.png" medium="image">
			<media:title type="html">PGConf.EU</media:title>
		</media:content>
	</item>
		<item>
		<title>How to move data from one schema to another in Postgres?</title>
		<link>http://pgolub.wordpress.com/2012/10/02/how-to-move-data-from-one-schema-to-another-in-postgres/</link>
		<comments>http://pgolub.wordpress.com/2012/10/02/how-to-move-data-from-one-schema-to-another-in-postgres/#comments</comments>
		<pubDate>Tue, 02 Oct 2012 07:42:42 +0000</pubDate>
		<dc:creator>pashagolub</dc:creator>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[trick]]></category>

		<guid isPermaLink="false">http://pgolub.wordpress.com/?p=1790</guid>
		<description><![CDATA[I saw a question today : I have PostpreSQL 9.1. In my database there are 2 schemas: public and test. How can I quickly move all objects and data from public to test? Opps. I&#8217;m stuck with this issue for<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://pgolub.wordpress.com/2012/10/02/how-to-move-data-from-one-schema-to-another-in-postgres/">Read more &#8250;</a></div><!-- end of .read-more --><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pgolub.wordpress.com&#038;blog=5816673&#038;post=1790&#038;subd=pgolub&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I saw a question today :</p>
<blockquote><p>I have PostpreSQL 9.1. In my database there are 2 schemas: <em>public</em> and <em>test</em>. How can I quickly move all objects and data from <em>public </em>to <em>test</em>?</p></blockquote>
<p>Opps. I&#8217;m stuck with this issue for some time. I was thinking about dump and restore tricks, about direct changes to the <em>pg_catalog</em> schema etc. I even appeared on the <a href="irc://irc.freenode.net/postgresql">IRC channel</a> with this question. </p>
<p>There I had conversation with Jon SuckMojo Erdman, who&#8217;s first thought was dump way either. But then we have found a simple and elegant solution independently.</p>
<p>Assuming schema <em>test</em> is empty:</p>
<table style="border-collapse:collapse;margin-top:15px;margin-bottom:15px;" border="0" cellspacing="0" cellpadding="5" bgcolor="LightYellow">
<tbody>
<tr>
<td>
<pre>
<strong>DROP SCHEMA</strong> test; 

<strong>ALTER SCHEMA</strong> public <strong>RENAME TO</strong> test; 

<strong>CREATE SCHEMA</strong> public; 
</pre>
</td>
</tr>
</tbody>
</table>
<p>Booyah!</p>
<br />Filed under: <a href='http://pgolub.wordpress.com/category/postgresql/'>PostgreSQL</a> Tagged: <a href='http://pgolub.wordpress.com/tag/postgresql/'>PostgreSQL</a>, <a href='http://pgolub.wordpress.com/tag/trick/'>trick</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pgolub.wordpress.com&#038;blog=5816673&#038;post=1790&#038;subd=pgolub&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://pgolub.wordpress.com/2012/10/02/how-to-move-data-from-one-schema-to-another-in-postgres/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/24a7da587040285b6213974ed8933fdf?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">pashagolub</media:title>
		</media:content>
	</item>
		<item>
		<title>Backward compatibility? Never heard of it!</title>
		<link>http://pgolub.wordpress.com/2012/06/22/backward-compatibility-never-heard-of-it/</link>
		<comments>http://pgolub.wordpress.com/2012/06/22/backward-compatibility-never-heard-of-it/#comments</comments>
		<pubDate>Fri, 22 Jun 2012 14:35:40 +0000</pubDate>
		<dc:creator>pashagolub</dc:creator>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[beta]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[pg9.2beta]]></category>

		<guid isPermaLink="false">http://pgolub.wordpress.com/?p=1777</guid>
		<description><![CDATA[Playing with fresh PostgreSQL 9.2beta2 I cannot find spclocation column of a system catalog pg_tablespace. First my thought was that I&#8217;m too tired. But then I found mentioning about this at pgsql-hackers by Magnus Hagander: And IIRC, we don&#8217;t actually<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://pgolub.wordpress.com/2012/06/22/backward-compatibility-never-heard-of-it/">Read more &#8250;</a></div><!-- end of .read-more --><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pgolub.wordpress.com&#038;blog=5816673&#038;post=1777&#038;subd=pgolub&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Playing with fresh PostgreSQL 9.2beta2 I cannot find <em>spclocation</em> column of a system catalog <a href="http://www.postgresql.org/docs/9.1/static/catalog-pg-tablespace.html">pg_tablespace</a>. First my thought was that I&#8217;m too tired. But then I found mentioning about this at <a href="http://archives.postgresql.org/pgsql-docs/2011-12/msg00006.php">pgsql-hackers</a> by Magnus Hagander:</p>
<blockquote><p>And IIRC, we don&#8217;t actually *use* spclocation anywhere. How about we<br />
just get rid of them as independents?</p></blockquote>
<p>Oh, really?!!! WTF? How about other developers, ha? I&#8217;m using this. I really do. Don&#8217;t know how about other guys, but I will need additional nasty checks for server version to know what should I use: <em>pg_get_tablespace_location(oid)</em> or <em>tablespace.spclocation</em></p>
<p>Thanks a lot guys! Way to go!</p>
<br />Filed under: <a href='http://pgolub.wordpress.com/category/postgresql/'>PostgreSQL</a> Tagged: <a href='http://pgolub.wordpress.com/tag/beta/'>beta</a>, <a href='http://pgolub.wordpress.com/tag/development/'>development</a>, <a href='http://pgolub.wordpress.com/tag/pg9-2beta/'>pg9.2beta</a>, <a href='http://pgolub.wordpress.com/tag/postgresql/'>PostgreSQL</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pgolub.wordpress.com&#038;blog=5816673&#038;post=1777&#038;subd=pgolub&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://pgolub.wordpress.com/2012/06/22/backward-compatibility-never-heard-of-it/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/24a7da587040285b6213974ed8933fdf?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">pashagolub</media:title>
		</media:content>
	</item>
		<item>
		<title>PG 9.2beta2 installation on Windows XP fails? Don&#8217;t worry!</title>
		<link>http://pgolub.wordpress.com/2012/06/22/pg-9-2beta2-installation-on-windows-xp-fails-dont-worry/</link>
		<comments>http://pgolub.wordpress.com/2012/06/22/pg-9-2beta2-installation-on-windows-xp-fails-dont-worry/#comments</comments>
		<pubDate>Fri, 22 Jun 2012 13:40:27 +0000</pubDate>
		<dc:creator>pashagolub</dc:creator>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[install]]></category>
		<category><![CDATA[pg9.2beta]]></category>

		<guid isPermaLink="false">http://pgolub.wordpress.com/?p=1775</guid>
		<description><![CDATA[Shit happens guys. And sometimes PostgreSQL windows installer fails. Now I&#8217;m talking about EnterpriseDB One-Click Installer for PostgreSQL 9.2beta2 particularly. As for me, I got &#8220;An error occurred executing the Microsoft VC++ runtime installer&#8221; message. Strange. I have a holy<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://pgolub.wordpress.com/2012/06/22/pg-9-2beta2-installation-on-windows-xp-fails-dont-worry/">Read more &#8250;</a></div><!-- end of .read-more --><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pgolub.wordpress.com&#038;blog=5816673&#038;post=1775&#038;subd=pgolub&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Shit happens guys. And sometimes PostgreSQL windows installer fails. Now I&#8217;m talking about <a href="http://www.enterprisedb.com/products-services-training/pgdevdownload#windows">EnterpriseDB One-Click Installer for PostgreSQL 9.2beta2</a> particularly. </p>
<p>As for me, I got &#8220;An error occurred executing the Microsoft VC++ runtime installer&#8221; message. Strange. I have a holy zoo of different runtimes on my test machine. </p>
<p>For those of you who need my advice. Run installer with additional parameter:</p>
<pre>
postgresql-9.2.0-beta2-windows.exe --install_runtimes 0
</pre>
<p>This will run installer without VC runtime check. </p>
<p>PS If you&#8217;ll need VC runtime you always may find it on the <a href="http://www.microsoft.com/en-us/download/details.aspx?id=5555">MS official site</a>. </p>
<br />Filed under: <a href='http://pgolub.wordpress.com/category/postgresql/'>PostgreSQL</a> Tagged: <a href='http://pgolub.wordpress.com/tag/install/'>install</a>, <a href='http://pgolub.wordpress.com/tag/pg9-2beta/'>pg9.2beta</a>, <a href='http://pgolub.wordpress.com/tag/postgresql/'>PostgreSQL</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pgolub.wordpress.com&#038;blog=5816673&#038;post=1775&#038;subd=pgolub&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://pgolub.wordpress.com/2012/06/22/pg-9-2beta2-installation-on-windows-xp-fails-dont-worry/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/24a7da587040285b6213974ed8933fdf?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">pashagolub</media:title>
		</media:content>
	</item>
		<item>
		<title>The tale of how PostgresDAC became the cross-platform component suite</title>
		<link>http://pgolub.wordpress.com/2012/02/20/the-tale-of-how-postgresdac-became-the-cross-platform-component-suite/</link>
		<comments>http://pgolub.wordpress.com/2012/02/20/the-tale-of-how-postgresdac-became-the-cross-platform-component-suite/#comments</comments>
		<pubDate>Mon, 20 Feb 2012 08:40:49 +0000</pubDate>
		<dc:creator>pashagolub</dc:creator>
				<category><![CDATA[PostgresDAC]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[component]]></category>
		<category><![CDATA[Delphi]]></category>
		<category><![CDATA[macos]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://pgolub.wordpress.com/?p=1743</guid>
		<description><![CDATA[As some probably know Delphi XE2 now have compilers for Win32, Win64, Mac and iOS. And as you probably guessed, we were inundated with questions from our customers about support for this zoo in our DACs. Frankly speaking this situation<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://pgolub.wordpress.com/2012/02/20/the-tale-of-how-postgresdac-became-the-cross-platform-component-suite/">Read more &#8250;</a></div><!-- end of .read-more --><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pgolub.wordpress.com&#038;blog=5816673&#038;post=1743&#038;subd=pgolub&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>As some probably know <a href="http://edn.embarcadero.com/article/41593" target="_blank">Delphi XE2</a> now have compilers for Win32, Win64, Mac and iOS. And as you probably guessed, we were inundated with questions from our customers about support for this zoo in our <a href="http://microolap.com/products/connectivity/" target="_blank">DACs</a>.</p>
<p>Frankly speaking this situation is perfectly described in Joel&#8217;s Spolsky <a href="http://www.joelonsoftware.com/articles/fog0000000339.html" target="_blank">&#8220;Fire and motion&#8221;</a>. We thought: &#8220;This just can&#8217;t be done in a sane time!&#8221;</p>
<p>However &#8220;you never know what you can do till you try&#8221; and &#8220;the devil is not so black as he is painted&#8221;. So we decided to port <a href="http://microolap.com/products/connectivity/postgresdac/" target="_blank">PostgresDAC</a> first. The main reason was the using of libpq.dll client library, which may be <a href="http://www.pgbuildfarm.org/cgi-bin/show_status.pl" target="_blank">built</a> for a huge amount of target platforms.</p>
<p>Thus we don&#8217;t need to worry about low-level network routines and may pay the whole of the attention to the middle layer, have no idea how to name it.</p>
<p><a href="http://pgolub.files.wordpress.com/2012/02/osx.png"><img class="alignright wp-image-1746" title="PostgresDAC target platforms" src="http://pgolub.files.wordpress.com/2012/02/osx.png?w=605" alt="" /></a>As for Win64 platform, then were no problems at all. We&#8217;ve prepared x64 deploy libraries and we done with it. There were no dangerous places in our source code were address arithmetics may produce unsuspected behavior. This simplicity is understandable. We just stayed within one Windows platform in general.</p>
<p>Then it was Mac&#8217;s turn. When we started I have never seen MacOS before&#8230; That was scary move. Especially for my self-esteem. <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>We crossed the fingers, chose OS X as the target platform and the fun began. I knew our code was Windows-centric, but I was so far from the real understanding of the scope of the tragedy. <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Here is the seven deadly sins for the cross-platform library written in Delphi:</p>
<p><strong>1.</strong> Using of <em>Windows</em> unit is prohibited. The only things you have are <em>System </em>ans <em>SysUtils</em>. Deal with it!</p>
<p><strong>2.</strong> Using of VCL units (<em>Controls, StdVCL, ExtCtrls</em> etc) is prohibited. There&#8217;s no VCL on Mac, <a href="http://www.embarcadero.com/products/firemonkey">FireMonkey</a> only.</p>
<p><strong>3.</strong> Using of forms is prohibited. So no custom dialogs, message boxes etc. You have no idea under which platform library is built. Well, this is so true for console application too. That&#8217;s why we&#8217;ve removed annoying trial screen.</p>
<p><strong>4.</strong> Ignoring compiler directives is stupid. Remember the first sin? Yeah, sometimes you&#8217;ll need low-level OS&#8217;s functionality. If so, do it smart:<br />
<code><br />
{$IFDEF MSWINDOWS}<br />
  Winapi.Windows,<br />
{$ENDIF}<br />
{$IFDEF MACOS}<br />
Macapi.CoreServices,<br />
{$ENDIF}<br />
{$IFDEF POSIX}<br />
  Posix.SysTypes, Posix.Stdio, Posix.Stdlib<br />
{$ENDIF}<br />
</code></p>
<p><strong>5.</strong> Using of messages, window procedures, handles, file mappings and other Win-shit is prohibited. That&#8217;s why our <a href="http://microolap.com/products/connectivity/postgresdac/help/TPSQLMonitor/TPSQLMonitor.htm" target="_blank">TPSQLMonitor</a> is still useless for Mac. We need to rewrite it from scratch. And we ready for it.</p>
<p><strong>6.</strong> Use correct type naming, e.g. <em>LongWord </em>instead of <em>DWORD</em>.</p>
<p><strong>7.</strong> Use proper functions or implement them for all platforms. No place for <em>ZeroMemory, CopyMemory, GetTickCount</em> on Mac etc.</p>
<p>You know, when I wrote the number of seven I didn&#8217;t think that I&#8217;m so damn write! Of course in your case there may be dozen of others incompatibilities. That was just a joke. <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<br />Filed under: <a href='http://pgolub.wordpress.com/category/postgresql/postgresdac/'>PostgresDAC</a>, <a href='http://pgolub.wordpress.com/category/postgresql/'>PostgreSQL</a> Tagged: <a href='http://pgolub.wordpress.com/tag/component/'>component</a>, <a href='http://pgolub.wordpress.com/tag/delphi/'>Delphi</a>, <a href='http://pgolub.wordpress.com/tag/macos/'>macos</a>, <a href='http://pgolub.wordpress.com/tag/osx/'>osx</a>, <a href='http://pgolub.wordpress.com/tag/postgresdac/'>PostgresDAC</a>, <a href='http://pgolub.wordpress.com/tag/windows/'>Windows</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pgolub.wordpress.com&#038;blog=5816673&#038;post=1743&#038;subd=pgolub&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://pgolub.wordpress.com/2012/02/20/the-tale-of-how-postgresdac-became-the-cross-platform-component-suite/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/24a7da587040285b6213974ed8933fdf?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">pashagolub</media:title>
		</media:content>

		<media:content url="http://pgolub.files.wordpress.com/2012/02/osx.png" medium="image">
			<media:title type="html">PostgresDAC target platforms</media:title>
		</media:content>
	</item>
		<item>
		<title>LibreOffice announces native support for PostgreSQL</title>
		<link>http://pgolub.wordpress.com/2012/02/15/libreoffice-announces-native-support-for-postgresql/</link>
		<comments>http://pgolub.wordpress.com/2012/02/15/libreoffice-announces-native-support-for-postgresql/#comments</comments>
		<pubDate>Wed, 15 Feb 2012 15:11:08 +0000</pubDate>
		<dc:creator>pashagolub</dc:creator>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[libpq]]></category>
		<category><![CDATA[libpq.dll]]></category>
		<category><![CDATA[LibreOffice]]></category>

		<guid isPermaLink="false">http://pgolub.wordpress.com/?p=1739</guid>
		<description><![CDATA[Today I found out about new release of LibreOffice (version 3.5), which is now my choice instead of MS Office and it&#8217;s brother OpenOffice killed by Oracle. And the most pleasant surprise is PostgreSQL native support added in this minor<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://pgolub.wordpress.com/2012/02/15/libreoffice-announces-native-support-for-postgresql/">Read more &#8250;</a></div><!-- end of .read-more --><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pgolub.wordpress.com&#038;blog=5816673&#038;post=1739&#038;subd=pgolub&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Today I found out about new release of LibreOffice (<a href="http://www.libreoffice.org/download/3-5-new-features-and-fixes/">version 3.5</a>), which is now my choice instead of MS Office and it&#8217;s brother OpenOffice killed by Oracle.</p>
<p>And the most pleasant surprise is PostgreSQL native support added in this minor release.<br />
<img alt="" src="http://www.libreoffice.org/assets/Uploads/EN-Project_images/3.5NewFeatures/Base/postgresql.png" class="aligncenter" width="690" height="484" /><br />
I remember messages by Lionel Elie Mamane sent to pgsql-hackers list. And the problems LibO community was faced with. Kudos guys!</p>
<p>BTW, how did you manage cross platform compilation of libpq library, especially for MacOS? And how do you provide libpq.so on Macs? </p>
<br />Filed under: <a href='http://pgolub.wordpress.com/category/postgresql/'>PostgreSQL</a> Tagged: <a href='http://pgolub.wordpress.com/tag/libpq/'>libpq</a>, <a href='http://pgolub.wordpress.com/tag/libpqdll/'>libpq.dll</a>, <a href='http://pgolub.wordpress.com/tag/libreoffice/'>LibreOffice</a>, <a href='http://pgolub.wordpress.com/tag/postgresql/'>PostgreSQL</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pgolub.wordpress.com&#038;blog=5816673&#038;post=1739&#038;subd=pgolub&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://pgolub.wordpress.com/2012/02/15/libreoffice-announces-native-support-for-postgresql/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/24a7da587040285b6213974ed8933fdf?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">pashagolub</media:title>
		</media:content>

		<media:content url="http://www.libreoffice.org/assets/Uploads/EN-Project_images/3.5NewFeatures/Base/postgresql.png" medium="image" />
	</item>
		<item>
		<title>Factorial using CTE in PostgreSQL</title>
		<link>http://pgolub.wordpress.com/2012/02/01/factorial-using-cte-in-postgresql/</link>
		<comments>http://pgolub.wordpress.com/2012/02/01/factorial-using-cte-in-postgresql/#comments</comments>
		<pubDate>Wed, 01 Feb 2012 09:42:26 +0000</pubDate>
		<dc:creator>pashagolub</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[CTE]]></category>
		<category><![CDATA[factorial]]></category>
		<category><![CDATA[oscon]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[trick]]></category>

		<guid isPermaLink="false">http://pgolub.wordpress.com/?p=1730</guid>
		<description><![CDATA[Not so long ago I used Common Table Expressions for Fibonacci Numbers calculation. Today I had a conversation with one client about SQL in general and about PosgreSQL dialect in particular. We talked about SQL&#8217;s Turing completeness also. Well my<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://pgolub.wordpress.com/2012/02/01/factorial-using-cte-in-postgresql/">Read more &#8250;</a></div><!-- end of .read-more --><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pgolub.wordpress.com&#038;blog=5816673&#038;post=1730&#038;subd=pgolub&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Not so long ago <a href="http://pgolub.wordpress.com/2010/06/20/fibonacci-rides-again/">I used</a> Common Table Expressions for <a href="http://en.wikipedia.org/wiki/Fibonacci_number">Fibonacci Numbers</a> calculation.</p>
<p>Today I had a conversation with one client about SQL in general and about PosgreSQL dialect in particular. We talked about SQL&#8217;s <a href="http://en.wikipedia.org/wiki/Turing_completeness">Turing completeness</a> also. Well my opponent is sure that SQL (Postgres dialect either) is not Turing Complete. But I know for sure that if SQL supports CTE it is Turing Complete. Well, I&#8217;m sure about it because some time ago at <a href="http://www.oscon.com/oscon2009">Oscon 2009</a> David Fetter said so. And my confidence in this man is boundless.  <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
<img alt="" src="http://habrastorage.org/storage2/8e8/001/13c/8e800113cf3071f21c26c0de1aff577c.png" title="Result set" class="alignright" width="106" height="287" /><br />
Anyway, my client proposed to implement Factorial calculation on a pure SQL. I choose Postgres dialect. He agreed. </p>
<p>That was his first mistake! He didn&#8217;t know that Postgres has built in <a href="http://www.postgresql.org/docs/9.1/static/functions-math.html">&#8220;!&#8221; and &#8220;!!&#8221; operators</a> for this purpose. <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>But to be more convincing, I have wrote this code:</p>
<table style="border-collapse:collapse;margin-top:15px;margin-bottom:15px;" border="0" cellspacing="0" cellpadding="5" bgcolor="LightYellow">
<tbody>
<tr>
<td>
<pre>
WITH RECURSIVE fact(i, f) AS (
    VALUES (2, 1)
UNION ALL
    SELECT i + 1, i * f FROM fact
)
SELECT f FROM fact LIMIT 10;
</pre>
</td>
</tr>
</tbody>
</table>
<br />Filed under: <a href='http://pgolub.wordpress.com/category/postgresql/coding/'>Coding</a>, <a href='http://pgolub.wordpress.com/category/postgresql/'>PostgreSQL</a> Tagged: <a href='http://pgolub.wordpress.com/tag/cte/'>CTE</a>, <a href='http://pgolub.wordpress.com/tag/factorial/'>factorial</a>, <a href='http://pgolub.wordpress.com/tag/oscon/'>oscon</a>, <a href='http://pgolub.wordpress.com/tag/postgresql/'>PostgreSQL</a>, <a href='http://pgolub.wordpress.com/tag/sql/'>SQL</a>, <a href='http://pgolub.wordpress.com/tag/trick/'>trick</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pgolub.wordpress.com&#038;blog=5816673&#038;post=1730&#038;subd=pgolub&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://pgolub.wordpress.com/2012/02/01/factorial-using-cte-in-postgresql/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/24a7da587040285b6213974ed8933fdf?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">pashagolub</media:title>
		</media:content>

		<media:content url="http://habrastorage.org/storage2/8e8/001/13c/8e800113cf3071f21c26c0de1aff577c.png" medium="image">
			<media:title type="html">Result set</media:title>
		</media:content>
	</item>
	</channel>
</rss>
