<?xml version="1.0" encoding="utf-8" ?>

<rss version="2.0" 
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:admin="http://webns.net/mvcb/"
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
   xmlns:wfw="http://wellformedweb.org/CommentAPI/"
   xmlns:content="http://purl.org/rss/1.0/modules/content/"
   >
<channel>
    <title>Postgres OnLine Journal (Entries tagged as common table expressions)</title>
    <link>http://www.postgresonline.com/journal/</link>
    <description>an In depth look at the PostgreSQL open source database</description>
    <dc:language>en</dc:language>
    <generator>Serendipity 1.4.1 - http://www.s9y.org/</generator>
    <pubDate>Fri, 15 Feb 2013 04:37:09 GMT</pubDate>

    <image>
        <url>http://www.postgresonline.com/journal/templates/default/img/s9y_banner_small.png</url>
        <title>RSS: Postgres OnLine Journal - an In depth look at the PostgreSQL open source database</title>
        <link>http://www.postgresonline.com/journal/</link>
        <width>100</width>
        <height>21</height>
    </image>

<item>
    <title>Saying Happy Valentine in PostGIS</title>
    <link>http://www.postgresonline.com/journal/archives/293-Saying-Happy-Valentine-in-PostGIS.html</link>
            <category>advanced</category>
            <category>application development</category>
            <category>cte</category>
            <category>postgis</category>
            <category>window functions</category>
    
    <comments>http://www.postgresonline.com/journal/archives/293-Saying-Happy-Valentine-in-PostGIS.html#comments</comments>
    <wfw:comment>http://www.postgresonline.com/journal/wfwcomment.php?cid=293</wfw:comment>

    <slash:comments>3</slash:comments>
    <wfw:commentRss>http://www.postgresonline.com/journal/rss.php?version=2.0&amp;type=comments&amp;cid=293</wfw:commentRss>
    

    <author>nospam@example.com (Leo Hsu and Regina Obe)</author>
    <content:encoded>
    &lt;p&gt;A while back I mentioned to Bborie (aka dustymugs) and Sandro (aka strk): &lt;em&gt;We&#039;re missing ability to label our images with text. 
Picture this: What if someone has got a road or a parcel of land and they want to stamp
the parcel id or the road name on it and they don&#039;t want to have to depend on some piece of mapping software.&lt;/em&gt;  Many report writers and databases can talk to each other directly 
such as we demonstrated in &lt;a href=&quot;http://www.postgresonline.com/journal/archives/244-Rendering-PostGIS-Raster-graphics-with-LibreOffice-Base-Reports.html&quot; target=&quot;_blank&quot;&gt;Rendering PostGIS raster graphics with LibreOffice&lt;/a&gt;
and we&#039;ve got raster functionality in the database already. Can we cut out the middleman?
Some ideas came to mind. One we could embed a font lib into PostGIS thus having the ultimate bloatware minus the built-in coffee maker.  
&lt;em&gt;strk screeched&lt;/em&gt;. He&#039;s still recovering from my constant demands of having him upgrade his PostgreSQL version.  Okay fair enough. &lt;/p&gt;
&lt;p&gt;Bborie suggested &lt;em&gt;why don&#039;t you import your letters as rasters and then vectorize them&lt;/em&gt;.  So that&#039;s exactly what we are going to demonstrate in this article
and in doing so we will combine some of the new features coming in PostGIS 2.1 we&#039;ve been talking about in &lt;a href=&quot;http://www.bostongis.com/blog/index.php?/categories/21-waiting_postgis_21&quot; target=&quot;_blank&quot;&gt;Waiting for PostGIS 2.1 series&lt;/a&gt;.&lt;/p&gt;
&lt;div style=&#039;background-color:yellow&#039;&gt;Warning this article will have a hint of &lt;a href=&quot;http://www.rubegoldberg.com/&quot; target=&quot;_blank&quot;&gt;Rube Goldbergishness&lt;/a&gt; in it.
If you are easily offended by seeing stupid tricks done with SQL, stop reading now.
We are going to take a natural vector product and rasterize it just so 
we can vectorize it again so we can then rasterize it again.  Don&#039;t think about it too much.  It may trigger activity in parts of your brain you didn&#039;t know were there
thus resulting in stabbing pains similar to what you experience by quickly guplping down a handful of Wasabi peas.&lt;/div&gt; 
So here are the steps for creating your own font set you can 
overlay on your geometries and rasters.&lt;/p&gt;
&lt;p&gt;See if you can spot the use of window functions and CTEs in these examples.&lt;/p&gt; &lt;br /&gt;&lt;a href=&quot;http://www.postgresonline.com/journal/archives/293-Saying-Happy-Valentine-in-PostGIS.html#extended&quot;&gt;Continue reading &quot;Saying Happy Valentine in PostGIS&quot;&lt;/a&gt;
    </content:encoded>

    <pubDate>Thu, 14 Feb 2013 02:44:00 -0500</pubDate>
    <guid isPermaLink="false">http://www.postgresonline.com/journal/archives/293-guid.html</guid>
    <category>ansi sql</category>
<category>common table expressions</category>
<category>row_number</category>
<category>window functions</category>

</item>
<item>
    <title>Foreign Data Wrap (FDW) Text Array, hstore, and Jagged Arrays</title>
    <link>http://www.postgresonline.com/journal/archives/259-Foreign-Data-Wrap-FDW-Text-Array,-hstore,-and-Jagged-Arrays.html</link>
            <category>9.1</category>
            <category>9.2</category>
            <category>contrib spotlight</category>
            <category>cte</category>
            <category>fdws</category>
            <category>hstore</category>
            <category>postgresql versions</category>
    
    <comments>http://www.postgresonline.com/journal/archives/259-Foreign-Data-Wrap-FDW-Text-Array,-hstore,-and-Jagged-Arrays.html#comments</comments>
    <wfw:comment>http://www.postgresonline.com/journal/wfwcomment.php?cid=259</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://www.postgresonline.com/journal/rss.php?version=2.0&amp;type=comments&amp;cid=259</wfw:commentRss>
    

    <author>nospam@example.com (Leo Hsu and Regina Obe)</author>
    <content:encoded>
    &lt;p&gt;As we discussed in &lt;a href=&quot;http://www.postgresonline.com/journal/archives/251-File-FDW-Family-Part-2-file_textarray_fdw-Foreign-Data-Wrapper.html&quot; target=&quot;_blank&quot;&gt;file_textarray_fdw Foreign Data Wrapper&lt;/a&gt;, &lt;a href=&quot;http://people.planetpostgresql.org/andrew/index.php?/archives/271-Deploying-file_text_array-Foreign-Data-wrapper.html&quot; target=&quot;_blank&quot;&gt;Andrew Dunstan&#039;s text array foreign data wrapper&lt;/a&gt; works great for bringing in a delimited file and not having to worry about the column names until they are in.
We had demonstrated one way to tag the field names to avoid having to keep track of index locations, by using hstore and the header column in conjunction.  
The problem with that is it doesn&#039;t work for jagged arrays.  Jagged arrays are when not all rows have the same number of columns. I&#039;ve jury rigged a small example
to demonstrate the issue.  Luckily with the power of PostgreSQL arrays you can usually get around this issue and still have nice names for your columns.  We&#039;ll demonstrate that too.&lt;/p&gt; &lt;br /&gt;&lt;a href=&quot;http://www.postgresonline.com/journal/archives/259-Foreign-Data-Wrap-FDW-Text-Array,-hstore,-and-Jagged-Arrays.html#extended&quot;&gt;Continue reading &quot;Foreign Data Wrap (FDW) Text Array, hstore, and Jagged Arrays&quot;&lt;/a&gt;
    </content:encoded>

    <pubDate>Sun, 15 Jul 2012 02:35:00 -0400</pubDate>
    <guid isPermaLink="false">http://www.postgresonline.com/journal/archives/259-guid.html</guid>
    <category>array</category>
<category>common table expressions</category>
<category>cte</category>
<category>file_textarray_fdw</category>
<category>foreign data wrapper</category>
<category>postgresql 9.1</category>

</item>
<item>
    <title>Finding contiguous primary keys</title>
    <link>http://www.postgresonline.com/journal/archives/255-Finding-contiguous-primary-keys.html</link>
            <category>8.4</category>
            <category>9.0</category>
            <category>9.1</category>
            <category>9.2</category>
            <category>intermediate</category>
            <category>postgresql versions</category>
            <category>q&amp;a</category>
    
    <comments>http://www.postgresonline.com/journal/archives/255-Finding-contiguous-primary-keys.html#comments</comments>
    <wfw:comment>http://www.postgresonline.com/journal/wfwcomment.php?cid=255</wfw:comment>

    <slash:comments>2</slash:comments>
    <wfw:commentRss>http://www.postgresonline.com/journal/rss.php?version=2.0&amp;type=comments&amp;cid=255</wfw:commentRss>
    

    <author>nospam@example.com (Leo Hsu and Regina Obe)</author>
    <content:encoded>
    &lt;p&gt;I recently had the need to figure out which ranges of my keys were contiguously numbered.  The related exercise is finding gaps in data as well.
Reasons might be because you need to determine what data did not get copied or what records got deleted.  There are lots of ways of accomplishing this, but this is the 
first that came to mind.  This approach uses window aggregates &lt;code&gt;lead&lt;/code&gt; function and common table expressions, so requires PostgreSQL 8.4+&lt;/p&gt; &lt;br /&gt;&lt;a href=&quot;http://www.postgresonline.com/journal/archives/255-Finding-contiguous-primary-keys.html#extended&quot;&gt;Continue reading &quot;Finding contiguous primary keys&quot;&lt;/a&gt;
    </content:encoded>

    <pubDate>Fri, 08 Jun 2012 16:29:00 -0400</pubDate>
    <guid isPermaLink="false">http://www.postgresonline.com/journal/archives/255-guid.html</guid>
    <category>common table expressions</category>
<category>cte</category>
<category>except</category>
<category>window</category>
<category>window functions</category>

</item>
<item>
    <title>String Aggregation in PostgreSQL, SQL Server, and MySQL</title>
    <link>http://www.postgresonline.com/journal/archives/191-String-Aggregation-in-PostgreSQL,-SQL-Server,-and-MySQL.html</link>
            <category>8.2</category>
            <category>8.3</category>
            <category>8.4</category>
            <category>9.0</category>
            <category>cte</category>
            <category>db2</category>
            <category>intermediate</category>
            <category>mysql</category>
            <category>oracle</category>
            <category>postgresql versions</category>
            <category>q&amp;a</category>
            <category>sql server</category>
            <category>window functions</category>
    
    <comments>http://www.postgresonline.com/journal/archives/191-String-Aggregation-in-PostgreSQL,-SQL-Server,-and-MySQL.html#comments</comments>
    <wfw:comment>http://www.postgresonline.com/journal/wfwcomment.php?cid=191</wfw:comment>

    <slash:comments>14</slash:comments>
    <wfw:commentRss>http://www.postgresonline.com/journal/rss.php?version=2.0&amp;type=comments&amp;cid=191</wfw:commentRss>
    

    <author>nospam@example.com (Leo Hsu and Regina Obe)</author>
    <content:encoded>
    &lt;p&gt;&lt;b&gt;Question:&lt;/b&gt; You have a table of people and a table that specifies the activities each person is involved
in.  You want to return a result that has one record per person and a column that has a listing of activities for each person
separated by semicolons and alphabetically sorted by activity. You also want the whole set alphabetically sorted by person&#039;s name. &lt;/p&gt;

&lt;p&gt;This is a question we are always asked and since we mentor on various flavors of databases, 
we need to be able to switch gears and provide an answer that works on the client&#039;s database. Most
often the additional requirement is that you can&#039;t install new functions in the database. This means that
for PostgreSQL/SQL Server that both support defining custom aggregates, that is out as an option.&lt;/p&gt;

&lt;p&gt;Normally we try to come up with an answer that works in most databases, but sadly the only solution that works in 
most is to push the problem off to the client front end and throw up your hands and proclaim -- &amp;quot;This ain&#039;t something that should be 
done in the database and is a reporting problem.&amp;quot;  That is in fact what many database purists do, and all I can say to them is wake up and smell the coffee before you are out of a job.  
We feel that data 
transformation is an important function of a database, and if your database is incapable of massaging the data into a format
your various client apps can easily digest, WELL THAT&#039;s A PROBLEM.&lt;/p&gt;

&lt;p&gt;We shall now document this answer rather than trying to answer for the nteenth time. For starter&#039;s
PostgreSQL has a lot of answers to this question, probably more so than any other, though some are easier to execute than others
and many depend on the version of PostgreSQL you are using.  SQL Server has 2 classes of answers neither of which is terribly appealing,
but we&#039;ll go over the ones that don&#039;t require you to be able to install .NET stored functions in your database since we said that is often a requirement.  
MySQL has a fairly
simple, elegant and very portable way that it has had for a really long time.&lt;/p&gt; &lt;br /&gt;&lt;a href=&quot;http://www.postgresonline.com/journal/archives/191-String-Aggregation-in-PostgreSQL,-SQL-Server,-and-MySQL.html#extended&quot;&gt;Continue reading &quot;String Aggregation in PostgreSQL, SQL Server, and MySQL&quot;&lt;/a&gt;
    </content:encoded>

    <pubDate>Fri, 24 Dec 2010 11:24:00 -0500</pubDate>
    <guid isPermaLink="false">http://www.postgresonline.com/journal/archives/191-guid.html</guid>
    <category>common table expressions</category>
<category>mysql</category>
<category>oracle</category>
<category>postgresql 9.0</category>
<category>sql server</category>
<category>string concatenation</category>
<category>window functions</category>

</item>
<item>
    <title>Using LTree to Represent and Query Hierarchy and Tree Structures</title>
    <link>http://www.postgresonline.com/journal/archives/173-Using-LTree-to-Represent-and-Query-Hierarchy-and-Tree-Structures.html</link>
            <category>8.2</category>
            <category>8.3</category>
            <category>8.4</category>
            <category>9.0</category>
            <category>contrib spotlight</category>
            <category>db2</category>
            <category>firebird</category>
            <category>intermediate</category>
            <category>ltree</category>
            <category>oracle</category>
            <category>postgresql versions</category>
            <category>sql server</category>
    
    <comments>http://www.postgresonline.com/journal/archives/173-Using-LTree-to-Represent-and-Query-Hierarchy-and-Tree-Structures.html#comments</comments>
    <wfw:comment>http://www.postgresonline.com/journal/wfwcomment.php?cid=173</wfw:comment>

    <slash:comments>5</slash:comments>
    <wfw:commentRss>http://www.postgresonline.com/journal/rss.php?version=2.0&amp;type=comments&amp;cid=173</wfw:commentRss>
    

    <author>nospam@example.com (Leo Hsu and Regina Obe)</author>
    <content:encoded>
    &lt;p&gt;PostgreSQL offers several options for displaying and querying tree like structures.  
In &lt;a href=&quot;http://www.postgresonline.com/journal/archives/131-Using-Recursive-Common-table-expressions-to-represent-Tree-structures.html&quot; target=&quot;_blank&quot;&gt;Using Recursive Common Table Expressions (CTE) to represent tree structures&lt;/a&gt;
we demonstrated how to use common table expressions to display a tree like structure.  Common Table Expressions required PostgreSQL 8.4 and above but  was fairly ANSI standards compliant. In addition to that 
approach you have the option of using recursive functions.  There is yet another common approach for this which is specific to PostgreSQL.  This is using the &lt;a href=&quot;http://www.postgresql.org/docs/current/static/ltree.html&quot; target=&quot;_blank&quot;&gt;ltree contrib datatype&lt;/a&gt;
that has been supported for sometime in PostgreSQL.  For one of our recent projects, we chose ltree over the other approaches because the performance is much better when you need to do ad-hoc queries over the tree since it can take advantage of btree and gist indexes
and also has built-in tree query expressions that make ad-hoc queries simpler to do; similar in concept to the tsearch query syntax for querying text. &lt;/p&gt;

&lt;p&gt;In this article we&#039;ll demonstrate how to use ltree and along the way also show the PostgreSQL 9.0 new features &lt;b&gt;conditional triggers&lt;/b&gt; and &lt;b&gt;ordered aggregates&lt;/b&gt;.&lt;/p&gt;
 &lt;br /&gt;&lt;a href=&quot;http://www.postgresonline.com/journal/archives/173-Using-LTree-to-Represent-and-Query-Hierarchy-and-Tree-Structures.html#extended&quot;&gt;Continue reading &quot;Using LTree to Represent and Query Hierarchy and Tree Structures&quot;&lt;/a&gt;
    </content:encoded>

    <pubDate>Sun, 22 Aug 2010 01:15:00 -0400</pubDate>
    <guid isPermaLink="false">http://www.postgresonline.com/journal/archives/173-guid.html</guid>
    <category>ansi sql</category>
<category>common table expressions</category>
<category>firebird</category>
<category>ibm db2</category>
<category>oracle</category>
<category>postgresql 9.0</category>
<category>sql server</category>
<category>triggers</category>

</item>
<item>
    <title>Allocating People into Groups with SQL the Sequel</title>
    <link>http://www.postgresonline.com/journal/archives/138-Allocating-People-into-Groups-with-SQL-the-Sequel.html</link>
            <category>8.4</category>
            <category>advanced</category>
            <category>cte</category>
            <category>postgresql versions</category>
            <category>q&amp;a</category>
            <category>window functions</category>
    
    <comments>http://www.postgresonline.com/journal/archives/138-Allocating-People-into-Groups-with-SQL-the-Sequel.html#comments</comments>
    <wfw:comment>http://www.postgresonline.com/journal/wfwcomment.php?cid=138</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://www.postgresonline.com/journal/rss.php?version=2.0&amp;type=comments&amp;cid=138</wfw:commentRss>
    

    <author>nospam@example.com (Leo Hsu and Regina Obe)</author>
    <content:encoded>
    &lt;p&gt;In our prior story about &lt;a href=&quot;http://www.postgresonline.com/journal/archives/137-Allocating-People-into-Groups-with-Window-aggregation.html&quot; target=&quot;_blank&quot;&gt;allocating people with the power of window aggregation&lt;/a&gt;, we saw our valiant hero and heroine trying
to sort people into elevators
to ensure that each elevator ride was not over capacity.  All was good in the world until someone named &lt;a href=&quot;http://www.postgresonline.com/journal/archives/137-Allocating-People-into-Groups-with-Window-aggregation.html#c1172&quot;&gt;Frank&lt;/a&gt; came along and spoiled the party.
Frank rightfully pointed out that our algorithm was flawed because should Charlie double his weight, then we could have one elevator ride over capacity.
We have a plan.
&lt;/p&gt; &lt;br /&gt;&lt;a href=&quot;http://www.postgresonline.com/journal/archives/138-Allocating-People-into-Groups-with-SQL-the-Sequel.html#extended&quot;&gt;Continue reading &quot;Allocating People into Groups with SQL the Sequel&quot;&lt;/a&gt;
    </content:encoded>

    <pubDate>Mon, 05 Oct 2009 00:55:00 -0400</pubDate>
    <guid isPermaLink="false">http://www.postgresonline.com/journal/archives/138-guid.html</guid>
    <category>common table expressions</category>
<category>ibm db2</category>
<category>oracle</category>
<category>sql server</category>

</item>
<item>
    <title>Using Recursive Common table expressions to represent Tree structures</title>
    <link>http://www.postgresonline.com/journal/archives/131-Using-Recursive-Common-table-expressions-to-represent-Tree-structures.html</link>
            <category>8.4</category>
            <category>basics</category>
            <category>cte</category>
            <category>intermediate</category>
    
    <comments>http://www.postgresonline.com/journal/archives/131-Using-Recursive-Common-table-expressions-to-represent-Tree-structures.html#comments</comments>
    <wfw:comment>http://www.postgresonline.com/journal/wfwcomment.php?cid=131</wfw:comment>

    <slash:comments>8</slash:comments>
    <wfw:commentRss>http://www.postgresonline.com/journal/rss.php?version=2.0&amp;type=comments&amp;cid=131</wfw:commentRss>
    

    <author>nospam@example.com (Leo Hsu and Regina Obe)</author>
    <content:encoded>
    &lt;p&gt;A very long time ago, we wrote an article on how to use PostgreSQL to show the fully qualified name of an item in an inventory tree.
Basically we were modeling a paper products tree. The original article can be found here &lt;a href=&quot;http://www.paragoncorporation.com/ArticleDetail.aspx?ArticleID=24&quot; target=&quot;_blank&quot;&gt;Using PostgreSQL User-Defined Functions to solve the Tree Problem&lt;/a&gt; and was based on PostgreSQL 7.4 technology.&lt;/p&gt;
&lt;p&gt;We&#039;ll repeat the text here for completeness and demonstrate the PostgreSQL 8.4 that solves this and more efficiently.&lt;/p&gt; &lt;br /&gt;&lt;a href=&quot;http://www.postgresonline.com/journal/archives/131-Using-Recursive-Common-table-expressions-to-represent-Tree-structures.html#extended&quot;&gt;Continue reading &quot;Using Recursive Common table expressions to represent Tree structures&quot;&lt;/a&gt;
    </content:encoded>

    <pubDate>Sun, 16 Aug 2009 13:44:00 -0400</pubDate>
    <guid isPermaLink="false">http://www.postgresonline.com/journal/archives/131-guid.html</guid>
    <category>common table expressions</category>

</item>
<item>
    <title>PostgresQL 8.4: Common Table Expressions (CTE), performance improvement, precalculated functions revisited</title>
    <link>http://www.postgresonline.com/journal/archives/127-PostgresQL-8.4-Common-Table-Expressions-CTE,-performance-improvement,-precalculated-functions-revisited.html</link>
            <category>basics</category>
            <category>cte</category>
            <category>db2</category>
            <category>firebird</category>
            <category>intermediate</category>
            <category>oracle</category>
            <category>sql server</category>
    
    <comments>http://www.postgresonline.com/journal/archives/127-PostgresQL-8.4-Common-Table-Expressions-CTE,-performance-improvement,-precalculated-functions-revisited.html#comments</comments>
    <wfw:comment>http://www.postgresonline.com/journal/wfwcomment.php?cid=127</wfw:comment>

    <slash:comments>6</slash:comments>
    <wfw:commentRss>http://www.postgresonline.com/journal/rss.php?version=2.0&amp;type=comments&amp;cid=127</wfw:commentRss>
    

    <author>nospam@example.com (Leo Hsu and Regina Obe)</author>
    <content:encoded>
    &lt;p&gt;Common table expressions are perhaps our favorite feature in PostgreSQL 8.4 even more so than windowing functions.  Strangely enough I find myself using them more in SQL Server too now that PostgreSQL supports it.&lt;/p&gt;
&lt;p&gt;CTEs are not only nice syntactic sugar, but they also produce better more efficient queries. To our knowledge only Firebird (see note below), PostgreSQL,SQL Server, and IBM DB2 support this, though I heard somewhere
that Oracle does too or is planning too &lt;span style=&#039;color:red&#039;&gt;UPDATE: As noted below Oracle as of version 9 supports non-recursive CTEs.  For recursion you need to use the Oracle proprietary corresponding by syntax&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;As far as CTEs go, the syntax between &lt;a hef=&quot;http://www.postgresql.org/docs/8.4/static/queries-with.html&quot; target=&quot;_blank&quot;&gt;PostgreSQL&lt;/a&gt;, &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/ms186243.aspx&quot; target=&quot;_blank&quot;&gt;SQL Server 2005/2008&lt;/a&gt;, &lt;a href=&quot;http://publib.boulder.ibm.com/infocenter/dzichelp/v2r2/index.jsp?topic=/com.ibm.db2.doc.sqlref/sscte.htm&quot; target=&quot;_blank&quot;&gt;IBM DB2&lt;/a&gt; and &lt;a href=&quot;http://firebirdsql.org/rlsnotesh/rlsnotes210.html#rnfb210-cte&quot; target=&quot;_blank&quot;&gt;Firebird&lt;/a&gt;
is pretty much the same when not using recursive queries.  When using recursive queries, PostgreSQL and Firebird use WITH RECURSIVE to denote a recursive CTE where as SQL Server and IBM DB2 its just WITH.&lt;/p&gt;
&lt;p&gt;All 4 databases allow you to have multiple table expressions within one WITH clause anda  RECURSIVE CTE expression can have both recursive and non-recursive CTEs.  This makes writing complex queries especially where you have the same expressions used multiple times in the query,
a lot easier to debug and also more performant.&lt;/p&gt;

&lt;p&gt;In our article on &lt;a href=&quot;http://www.postgresonline.com/journal/archives/113-How-to-force-PostgreSQL-to-use-a-pre-calculated-value.html&quot; target=&quot;_blank&quot;&gt;How to force PostgreSQL to use a pre-calculated value&lt;/a&gt;
we talked about techniques for forcing PostgreSQL to cache a highly costly function.  For PostgreSQL 8.3 and below, the winning solution was using OFFSET which is not terribly cross platform and has the disadvantage of
materializing the subselect. &lt;a href=&quot;http://fetter.org/&quot; target=&quot;_blank&quot;&gt;David Fetter&lt;/a&gt; had suggested
for 8.4, why not try CTEs.  Yes CTEs not only are syntactically nice, more portable, but they help you write more efficient queries.  To demonstrate, we shall repeat the same exercise we did in that
article, but using CTEs instead.&lt;/p&gt; &lt;br /&gt;&lt;a href=&quot;http://www.postgresonline.com/journal/archives/127-PostgresQL-8.4-Common-Table-Expressions-CTE,-performance-improvement,-precalculated-functions-revisited.html#extended&quot;&gt;Continue reading &quot;PostgresQL 8.4: Common Table Expressions (CTE), performance improvement, precalculated functions revisited&quot;&lt;/a&gt;
    </content:encoded>

    <pubDate>Thu, 16 Jul 2009 22:40:00 -0400</pubDate>
    <guid isPermaLink="false">http://www.postgresonline.com/journal/archives/127-guid.html</guid>
    <category>common table expressions</category>
<category>firebird</category>
<category>ibm db2</category>
<category>oracle</category>
<category>sql server</category>

</item>

</channel>
</rss>