<?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>Labix Blog &#187; PostgreSQL</title>
	<atom:link href="http://blog.labix.org/tag/postgresql/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.labix.org</link>
	<description>by Gustavo Niemeyer</description>
	<lastBuildDate>Fri, 09 Jul 2010 19:15:49 +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>Comparing package versions in PostgreSQL</title>
		<link>http://blog.labix.org/2006/07/30/comparing-package-versions-in-postgresql</link>
		<comments>http://blog.labix.org/2006/07/30/comparing-package-versions-in-postgresql#comments</comments>
		<pubDate>Mon, 31 Jul 2006 00:46:04 +0000</pubDate>
		<dc:creator>Gustavo Niemeyer</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Project]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://blog.labix.org/2006/07/30/comparing-package-versions-in-postgresql/</guid>
		<description><![CDATA[This weekend I&#8217;ve played a bit with PostgreSQL extensions written in C. A while ago I wrote a Python C extension for Smart to compare Debian package versions. Now I was trying to do something similar inside PostgreSQL, and thus &#8230; <a href="http://blog.labix.org/2006/07/30/comparing-package-versions-in-postgresql">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This weekend I&#8217;ve played a bit with <a href="http://www.postgresql.org/docs/8.1/interactive/extend.html">PostgreSQL extensions</a> written in C.</p>
<p>A while ago I wrote a Python C extension for <a href="http://labix.org/smart">Smart</a> to compare <a href="http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Version">Debian package versions</a>. Now I was trying to do something similar inside PostgreSQL, and thus ported the original Python C extension code to a PostgreSQL C extension. It enables queries like the following:</p>
<pre>
# SELECT 'Matched' WHERE deb_version_match('1.2', '<=', '2.0');
  ?column?
----------
 Matched
</pre>
<p>The implementation of the PostgreSQL C extension was quite straightforward, but I'm a bit disappointed by the performance of <a href="http://www.postgresql.org/docs/8.1/interactive/plpgsql.html">PL/PGSQL</a>.</p>
<p>I've made tests using two environments. One of them is a <a href="http://www.postgresql.org/docs/8.1/interactive/plpython.html">PL/Python</a> function executed as a <a href="http://www.postgresql.org/docs/8.1/interactive/triggers.html">trigger</a>, which calls the original Python C extension and executes SQL back in PostgreSQL using the <a href="http://www.postgresql.org/docs/8.1/interactive/plpython-database.html">plpy</a> module. The other is a  PL/PGSQL function which uses the implemented PostgreSQL C extension directly.</p>
<p>Considering that the function logic consisted of one loop over a SELECT statement, a few tests, and an INSERT statement, I was expecting that the overhead introduced by going back and forth between the PostgreSQL state and the Python interpreter state would be a lot more noticeable when compared with PL/PGSQL executing an internal PostgreSQL function. Tests have shown about 10% of improvement roughly, when doing a similar logic over about 5000 items.</p>
<p>I'm not yet sure if the speed improvement pays off the limited debugging feedback provided by the PL/PGSQL interpreter on errors.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.labix.org/2006/07/30/comparing-package-versions-in-postgresql/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
