<?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 - intermediate</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, 27 Aug 2010 23:15:02 GMT</pubDate>

    <image>
        <url>http://www.postgresonline.com/journal/templates/default/img/s9y_banner_small.png</url>
        <title>RSS: Postgres OnLine Journal - intermediate - 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>Explain Plans PostgreSQL 9.0 - Part 2: JSON and JQuery Plan Viewer</title>
    <link>http://www.postgresonline.com/journal/archives/174-Explain-Plans-PostgreSQL-9.0-Part-2-JSON-and-JQuery-Plan-Viewer.html</link>
            <category>9.0</category>
            <category>application development</category>
            <category>intermediate</category>
            <category>jquery</category>
            <category>pgadmin</category>
            <category>postgresql versions</category>
    
    <comments>http://www.postgresonline.com/journal/archives/174-Explain-Plans-PostgreSQL-9.0-Part-2-JSON-and-JQuery-Plan-Viewer.html#comments</comments>
    <wfw:comment>http://www.postgresonline.com/journal/wfwcomment.php?cid=174</wfw:comment>

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

    <author>nospam@example.com (Leo Hsu and Regina Obe)</author>
    <content:encoded>
    &lt;p&gt;In &lt;a href=&quot;http://www.postgresonline.com/journal/archives/171-pgexplain90formats_part1.html&quot; target=&quot;_blank&quot;&gt;part 1 of this series&lt;/a&gt; on PostgreSQL 9.0 planner outputs, we demonstrated how to render explain plans in YAML, JSON, and XML using the new explain features in PostgreSQL 9.0. In this second part,
we&#039;ll demonstrate how to build a user interface that allows you input a JSON formatted explain plan and have it render into a printable, navigateable display using JQuery, javascript and a little bit of HTML coding.  
In part 3 we&#039;ll do something similar using XML and XSLT programming.
&lt;/p&gt;
&lt;p&gt;For those who aren&#039;t familiar with JQuery, it is an MIT licensed javascript library that is fairly light weight and allows you to inspect and change html elements with fairly intuitive syntax, has some nice ajax methods and tools for converting xml/json to native objects that can be manipulated. 
You can check it out at &lt;a href=&quot;http://jquery.com/&quot; target=&quot;_blank&quot;&gt;JQUERY&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;We are not experts in JQuery, but from what we have used of it, we really like it and the fact the base package is MIT licensed, fairly light weight and lots of plugins available for it are real pluses.&lt;/p&gt;


&lt;p&gt;The most difficult thing I think most people find about reading explain plans is that they are upside down; it starts with a conclusion and backtracks how to arrive at it.  Humans by nature think about planning steps from start to finish.
In order to make an explain plan understandable to mere mortals, we generally display them upside down or having the child-nodes shown left most.  We shall follow that approach.&lt;/p&gt;
 &lt;br /&gt;&lt;a href=&quot;http://www.postgresonline.com/journal/archives/174-Explain-Plans-PostgreSQL-9.0-Part-2-JSON-and-JQuery-Plan-Viewer.html#extended&quot;&gt;Continue reading &quot;Explain Plans PostgreSQL 9.0 - Part 2: JSON and JQuery Plan Viewer&quot;&lt;/a&gt;
    </content:encoded>

    <pubDate>Thu, 26 Aug 2010 04:13:00 -0400</pubDate>
    <guid isPermaLink="false">http://www.postgresonline.com/journal/archives/174-guid.html</guid>
    <category>explain plan</category>
<category>imagemagick</category>
<category>jquery</category>
<category>json</category>
<category>pgadmin</category>
<category>postgresql 9.0</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>3</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>Fuzzy string matching with Trigram and Trigraphs</title>
    <link>http://www.postgresonline.com/journal/archives/169-Fuzzy-string-matching-with-Trigram-and-Trigraphs.html</link>
            <category>8.3</category>
            <category>8.4</category>
            <category>9.0</category>
            <category>contrib spotlight</category>
            <category>fuzzystrmatch</category>
            <category>intermediate</category>
            <category>pgtrgm</category>
            <category>postgresql versions</category>
    
    <comments>http://www.postgresonline.com/journal/archives/169-Fuzzy-string-matching-with-Trigram-and-Trigraphs.html#comments</comments>
    <wfw:comment>http://www.postgresonline.com/journal/wfwcomment.php?cid=169</wfw:comment>

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

    <author>nospam@example.com (Leo Hsu and Regina Obe)</author>
    <content:encoded>
    &lt;p&gt;In an earlier article &lt;a href=&quot;http://www.postgresonline.com/journal/archives/158-Where-is-soundex-and-other-warm-and-fuzzy-string-things.html&quot; target=&quot;_blank&quot;&gt;Where is Soundex and other Fuzzy string things&lt;/a&gt; we covered the PostgreSQL contrib module fuzzstrmatch which contains the very popular function
soundex that is found in other popular relational databases. We also covered  the more powerful levenshtein distance, metaphone and 
dmetaphone functions included in fuzzstrmatch, but rarely found in other relational databases.&lt;/p&gt;

&lt;p&gt;As far as fuzzy string matching goes, PostgreSQL has other functions up its sleeves.  This time we will cover
the contrib module &lt;a href=&quot;http://www.postgresql.org/docs/8.4/interactive/pgtrgm.html&quot; target=&quot;_blank&quot;&gt;pg_trgm&lt;/a&gt; which was introduced in PostgreSQL 8.3.  pgtrgm uses a concept called trigrams  for doing string comparisons. The pg_trgm module has several functions and gist/gin operators.  
Like other contrib modules, you just need to run the &lt;b&gt;/share/contrib/pg_trgm.sql&lt;/b&gt; file packaged in your PostgreSQL install to enable it in your database. 
&lt;/p&gt;
&lt;p&gt;For this set of exercises, we&#039;ll use trigrams to compare words using the same set of data we tested 
with soundex and metaphones. For the next set of exercises, we will be using the places dataset we created in &lt;a href=&quot;http://www.postgresonline.com/journal/archives/157-Import-fixed-width-data-into-PostgreSQL-with-just-PSQL.html&quot; target=&quot;_blank&quot;&gt;Importing Fixed width data into PostgreSQL with just PSQL&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt; The most useful are the &lt;B&gt;similarity&lt;/B&gt; function and the
% operator.  The &lt;b&gt;%&lt;/b&gt; operator allows for using a GIST/GIN index and the similarity function allows for narrowing your filter similar to what
levenshtein did for us in fuzzstrmatch.&lt;/p&gt; &lt;br /&gt;&lt;a href=&quot;http://www.postgresonline.com/journal/archives/169-Fuzzy-string-matching-with-Trigram-and-Trigraphs.html#extended&quot;&gt;Continue reading &quot;Fuzzy string matching with Trigram and Trigraphs&quot;&lt;/a&gt;
    </content:encoded>

    <pubDate>Wed, 21 Jul 2010 18:20:00 -0400</pubDate>
    <guid isPermaLink="false">http://www.postgresonline.com/journal/archives/169-guid.html</guid>
    <category>string matching</category>
<category>trigram</category>
<category>trigraph</category>

</item>
<item>
    <title>STRICT on SQL Function Breaks In-lining Gotcha</title>
    <link>http://www.postgresonline.com/journal/archives/163-STRICT-on-SQL-Function-Breaks-In-lining-Gotcha.html</link>
            <category>8.3</category>
            <category>8.4</category>
            <category>9.0</category>
            <category>basics</category>
            <category>intermediate</category>
            <category>mysql</category>
            <category>oracle</category>
            <category>postgis</category>
            <category>postgresql versions</category>
            <category>sql functions</category>
            <category>sql server</category>
    
    <comments>http://www.postgresonline.com/journal/archives/163-STRICT-on-SQL-Function-Breaks-In-lining-Gotcha.html#comments</comments>
    <wfw:comment>http://www.postgresonline.com/journal/wfwcomment.php?cid=163</wfw:comment>

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

    <author>nospam@example.com (Leo Hsu and Regina Obe)</author>
    <content:encoded>
    &lt;p&gt;One of the coolest features of PostgreSQL is the ability to write functions using plain old
SQL.  This feature it has had for a long time.  Even before PostgreSQL 8.2. No other database to our knowledge has this feature.  By SQL we mean sans procedural mumbo jumbo like
loops and what not.  This is cool for two reasons:&lt;/p&gt;

&lt;UL&gt;
	&lt;LI&gt;Plain old SQL is the simplest to write and most anyone can write one and is just what the doctor ordered in many cases. PostgreSQL even allows you to write
		aggregate functions with plain old SQL. Try to write an &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/ms131056(v=SQL.105).aspx&quot; target=&quot;_blank&quot;&gt;aggregate function in SQL Server&lt;/a&gt;
		you&#039;ve got to pull out your Visual Studio this and that and do some compiling and loading and you better know C# or VB.NET.  Try in &lt;a href=&quot;http://www.codeproject.com/KB/database/MySQL_UDFs.aspx&quot; target=&quot;_blank&quot;&gt;MySQL and you better learn C&lt;/a&gt;.
			Do the same in PostgreSQL (you have a large choice of languages &lt;a href=&quot;http://www.postgresonline.com/journal/archives/68-More-Aggregate-Fun-Whos-on-First-and-Whos-on-Last.html&quot; target=&quot;_blank&quot;&gt;including SQL&lt;/a&gt;) and the code is simple to write.  Nevermind
			with MySQL and SQL Server, you aren&#039;t even allowed to do those type of things on a shared server or a server where the IT department is paranoid.  The closest 
				with this much ease would be  &lt;a href=&quot;http://www.oracle.com/technology/oramag/oracle/06-jul/o46sql.html&quot; target=&quot;_blank&quot;&gt;Oracle, which is unnecessarily verbose&lt;/a&gt;. &lt;/LI&gt;
	&lt;LI&gt;Most importantly -- since it is just SQL, for simple user-defined functions, a PostgreSQL sql function can often be in-lined into the overall query plan since
		it only uses what is legal in plain old SQL.&lt;/LI&gt;
&lt;/UL&gt;

&lt;p&gt;This inlining feature is part of the secret sauce that makes PostGIS fast and easy to use.
So instead of writing geom1 &amp;&amp;amp; geom2 AND Intersects(geom1,geom2)  -- a user can write
ST_Intersects(geom1,geom2) .  The short-hand is even more striking when you think of the ST_DWithin function.
&lt;/p&gt;

&lt;p&gt;With an inlined function, the planner has visibility into the function and breaks apart the 
spatial index short-circuit test &amp;amp;&amp;amp;  from the more exhaustive absolute test Intersects(geom1,geom2)
and has great flexibility in reordering the clauses in the plan.
&lt;/p&gt; &lt;br /&gt;&lt;a href=&quot;http://www.postgresonline.com/journal/archives/163-STRICT-on-SQL-Function-Breaks-In-lining-Gotcha.html#extended&quot;&gt;Continue reading &quot;STRICT on SQL Function Breaks In-lining Gotcha&quot;&lt;/a&gt;
    </content:encoded>

    <pubDate>Wed, 02 Jun 2010 05:06:00 -0400</pubDate>
    <guid isPermaLink="false">http://www.postgresonline.com/journal/archives/163-guid.html</guid>
    
</item>
<item>
    <title>Forcing the planner's hand with set enable_seqscan off WTF</title>
    <link>http://www.postgresonline.com/journal/archives/149-Forcing-the-planners-hand-with-set-enable_seqscan-off-WTF.html</link>
            <category>8.3</category>
            <category>8.4</category>
            <category>intermediate</category>
            <category>postgresql versions</category>
            <category>q&amp;a</category>
    
    <comments>http://www.postgresonline.com/journal/archives/149-Forcing-the-planners-hand-with-set-enable_seqscan-off-WTF.html#comments</comments>
    <wfw:comment>http://www.postgresonline.com/journal/wfwcomment.php?cid=149</wfw:comment>

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

    <author>nospam@example.com (Leo Hsu and Regina Obe)</author>
    <content:encoded>
    &lt;p&gt;&lt;span style=&quot;color:green&quot;&gt;UPDATE: &lt;/span&gt;Thanks all for the suggestions.  For now we ended up increasing the
seq_page_cost from 1 to 2  in the database.  That has gotten us back to our old much much faster speeds without change in code and seems to have
improved the speeds of other queries as well, without reducing speed of any.

&lt;code&gt;ALTER DATABASE mydb SET seq_page_cost=2;&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;As Jeff suggested, we&#039;ll try to come up with a standalone example that exhibits the behavior.  The below example was more to demonstrate the construct.  Table names and fields were changed to protect the innocent so that is why we didn&#039;t bother showing explain plans.  The behavior also seems to do 
with the distribution of data and gets worse when stats are updated (via vacuum analyze).  Didn&#039;t see this in PostgreSQL 8.3 and this was a system recently upgraded from 8.3 to 8.4 &lt;/p&gt;
&lt;b&gt;---ORIGINAL ARTICLE HERE --&lt;/b&gt;&lt;br /&gt;
&lt;p&gt;This is a very odd thing and I think has happened to us perhaps once before.
Its a bit puzzling, and we aren&#039;t particularly happy with our work around because its
something that looks to a casual observer as a bit bizarre. The hack is setting the enable_seqscan setting
off for a particular query to force the planner to use indexes available to it.&lt;/p&gt;

&lt;p&gt;What is particularly troubling about this problem, is that it wasn&#039;t always this way.
This is a piece of query code we&#039;ve had in an application for a while, and its worked shall
I say &lt;em&gt;really fast&lt;/em&gt;.  Response times in 300 ms - 1 sec, for what is not a trivial query against a not
so trivially sized hierarchy of tables.  
Anyrate, one day -- this query that we were very happy with, suddenly started
hanging taking 5 minutes to run.  Sure data had been added and so forth, but that didn&#039;t 
completely explain this sudden change of behavior.  The plan it had taken had changed drastically.
It just suddenly decided to stop using a critical index it had always used.  Well it was still using it but just on 
the root table, not the children.  Though querying a child directly proved that it still refused to use it, 
so it didn&#039;t seem to be the hierarchy at fault here.&lt;/p&gt; &lt;br /&gt;&lt;a href=&quot;http://www.postgresonline.com/journal/archives/149-Forcing-the-planners-hand-with-set-enable_seqscan-off-WTF.html#extended&quot;&gt;Continue reading &quot;Forcing the planner&#039;s hand with set enable_seqscan off WTF&quot;&lt;/a&gt;
    </content:encoded>

    <pubDate>Sat, 09 Jan 2010 01:12:00 -0500</pubDate>
    <guid isPermaLink="false">http://www.postgresonline.com/journal/archives/149-guid.html</guid>
    <category>ansi sql</category>
<category>performance optimization</category>

</item>
<item>
    <title>Compiling PostGIS 1.5 and installing after Yum PostgreSQL Install</title>
    <link>http://www.postgresonline.com/journal/archives/147-Compiling-PostGIS-1.5-and-installing-after-Yum-PostgreSQL-Install.html</link>
            <category>basics</category>
            <category>gis</category>
            <category>intermediate</category>
            <category>postgis</category>
            <category>yum</category>
    
    <comments>http://www.postgresonline.com/journal/archives/147-Compiling-PostGIS-1.5-and-installing-after-Yum-PostgreSQL-Install.html#comments</comments>
    <wfw:comment>http://www.postgresonline.com/journal/wfwcomment.php?cid=147</wfw:comment>

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

    <author>nospam@example.com (Leo Hsu and Regina Obe)</author>
    <content:encoded>
    &lt;p&gt;A couple of people have asked this, so thought we would address the common issues people run into
with compiling PostGIS.&lt;/p&gt;

&lt;p&gt;The first question, some will ask is &lt;b&gt;Why don&#039;t you just take the packaged PostGIS that comes with the PostgreSQL
Yum repository?&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;There are two reasons for not installing PostGIS under using Yum and our general reasons for not.
&lt;UL&gt;&lt;LI&gt;We like running a newer GEOS than what is generally packaged with Yum because certain PostGIS functionality 
is not enabled with older versions of GEOS.  For example GEOS 3.1 introduced a couple of new functions like ST_Covers and
ST_CoveredBy, ST_ContainedProperly
the &lt;a href=&quot;http://blog.cleverelephant.ca/2009/01/must-faster-unions-in-postgis-14.html&quot; target=&quot;_bank&quot;&gt;Cascaded Union&lt;/a&gt; and &lt;a href=&quot;http://blog.cleverelephant.ca/2008/10/postgis-performance-prepared-geometry.html&quot; target=&quot;_blank&quot;&gt;prepared geometry&lt;/a&gt; speed enhancements  require GEOS 3.1+.  GEOS 3.2 brought more robust support for dealing with topological
exceptions, &lt;a href=&quot;http://www.postgis.org/documentation/manual-svn/ST_Buffer.html&quot; target=&quot;_blank&quot;&gt;new buffering features like one-sided buffer&lt;/a&gt; (which the upcoming PostGIS 1.5 exposes if and only if you are running
GEOS 3.2+), faster buffering, and several memory leak cleanups. We highly recommend using GEOS 3.2.0.  It is just a more robust product than prior GEOS versions.&lt;/LI&gt;

&lt;LI&gt;We generally like to run newer versions of PostGIS than what Yum provides and also run multiple versions of PostGIS
on the same server.  This is a bit tricky to do with Yum since it only exposes one and generally an older one than what we 
care for. PostGIS 1.5 will be especially great since it will have the &lt;a href=&quot;http://www.postgis.org/documentation/manual-svn/ch04.html#PostGIS_Geography&quot; target=&quot;_blank&quot;&gt;geodetic support&lt;/a&gt; and cool functions like &lt;a href=&quot;http://www.postgis.org/documentation/manual-svn/ST_ClosestPoint.html&quot; target=&quot;_blank&quot;&gt;ST_ClosestPoint&lt;/a&gt;
	and &lt;a href=&quot;http://www.postgis.org/documentation/manual-svn/ch08.html#NewFunctions_1_5&quot; target=&quot;_blank&quot;&gt;other major goodies&lt;/a&gt;.&lt;/LI&gt;
&lt;/UL&gt;
&lt;p&gt;&lt;b&gt;NOTE: PostGIS 1.3, PostGIS 1.4, PostGIS 1.5 can coexist on the same PostgreSQL daemon service as long as they are installed in different databases. They will all share the same Proj and GEOS. So installing PostGIS 1.5 will not break your
PostGIS 1.4 or 1.3 installs. The newer GEOS 3.2.0 C-API is backward compatible with older GEOS C-API and the C-API is what PostGIS uses.&lt;/b&gt;&lt;/p&gt; &lt;br /&gt;&lt;a href=&quot;http://www.postgresonline.com/journal/archives/147-Compiling-PostGIS-1.5-and-installing-after-Yum-PostgreSQL-Install.html#extended&quot;&gt;Continue reading &quot;Compiling PostGIS 1.5 and installing after Yum PostgreSQL Install&quot;&lt;/a&gt;
    </content:encoded>

    <pubDate>Fri, 01 Jan 2010 13:48:00 -0500</pubDate>
    <guid isPermaLink="false">http://www.postgresonline.com/journal/archives/147-guid.html</guid>
    
</item>
<item>
    <title>Allocating People into Groups with Window aggregation</title>
    <link>http://www.postgresonline.com/journal/archives/137-Allocating-People-into-Groups-with-Window-aggregation.html</link>
            <category>8.4</category>
            <category>intermediate</category>
            <category>postgis</category>
            <category>q&amp;a</category>
            <category>window functions</category>
    
    <comments>http://www.postgresonline.com/journal/archives/137-Allocating-People-into-Groups-with-Window-aggregation.html#comments</comments>
    <wfw:comment>http://www.postgresonline.com/journal/wfwcomment.php?cid=137</wfw:comment>

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

    <author>nospam@example.com (Leo Hsu and Regina Obe)</author>
    <content:encoded>
    &lt;p&gt;This is along the lines of more stupid window function fun and how many ways can we abuse this technology in PostgreSQL.  Well actually we were using this approach to allocate geographic areas such that each area has approximately the same population 
of things.  So you can imagine densely populated areas would have smaller regions and more of them  and less dense areas will have larger regions but fewer of them (kind of like US Census tracts). 
So you have to think about ways of allocating your regions so you don&#039;t have a multipolygon where one part is in one part of the world and the other in another etc.  Using window aggregation is one approach in conjunction with spatial sorting algorithms.
&lt;/p&gt;

&lt;p&gt;The non-spatial equivalent of this problem is how do you shove people in an elevator and ensure you don&#039;t exceed the capacity of the elevator for each ride.  Below is a somewhat naive way of doing this.
The idea being you keep on summing the weights until you reach capacity and then start a new grouping.&lt;/p&gt; &lt;br /&gt;&lt;a href=&quot;http://www.postgresonline.com/journal/archives/137-Allocating-People-into-Groups-with-Window-aggregation.html#extended&quot;&gt;Continue reading &quot;Allocating People into Groups with Window aggregation&quot;&lt;/a&gt;
    </content:encoded>

    <pubDate>Mon, 28 Sep 2009 15:58:00 -0400</pubDate>
    <guid isPermaLink="false">http://www.postgresonline.com/journal/archives/137-guid.html</guid>
    
</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>6</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>Use of OUT and INOUT Parameters</title>
    <link>http://www.postgresonline.com/journal/archives/129-Use-of-OUT-and-INOUT-Parameters.html</link>
            <category>8.2</category>
            <category>8.3</category>
            <category>8.4</category>
            <category>intermediate</category>
            <category>pl programming</category>
            <category>plpgsql</category>
            <category>postgresql versions</category>
            <category>sql functions</category>
    
    <comments>http://www.postgresonline.com/journal/archives/129-Use-of-OUT-and-INOUT-Parameters.html#comments</comments>
    <wfw:comment>http://www.postgresonline.com/journal/wfwcomment.php?cid=129</wfw:comment>

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

    <author>nospam@example.com (Leo Hsu and Regina Obe)</author>
    <content:encoded>
    &lt;p&gt;PostgreSQL has supported what are called Out (output) parameters &lt;a href=&quot;http://www.postgresql.org/docs/8.1/interactive/plpgsql-declarations.html&quot; target=&quot;_blank&quot;&gt;since version 8.1&lt;/a&gt;.
We were surprised it has been that long since we always thought of it as a feature from 8.2+ 
until it recently came up for discussion on &lt;a href=&quot;http://postgis.refractions.net/pipermail/postgis-users/2009-July/024104.html&quot; target=&quot;_blank&quot;&gt;PostGIS newsgroup&lt;/a&gt; and we decided to investigate how 
long it has been supported.
&lt;/p&gt;
&lt;p&gt;What are OUT parameters?  These are parameters you define as part of the function argument
list that get returned back as part of the result.  When you create functions, the arguments 
 are defaulted to IN parameters when not explicitly specified (which means they are passed in and not returned) which 
is why you sometimes see PgAdmin do something like &lt;em&gt;IN somevariable variabletype&lt;/em&gt; when you use 
the function wizard.
&lt;/p&gt;
&lt;p&gt;You can have INOUT parameters as well which are function inputs that both get passed in, can be modified
by the function and also get returned.&lt;/p&gt;

&lt;p&gt;As a side note -  In 8.4, PostgreSQL was enhanced to allow dynamic sql RETURN QUERY using &lt;a href=&quot;http://www.postgresql.org/docs/8.4/static/plpgsql-statements.html&quot; target=&quot;_blank&quot;&gt;RETURN QUERY EXECUTE&lt;/a&gt; syntax for plpgsql queries and also
allow set returning functions being called in the SELECT part for any pl language.  In prior versions,
this was only a feature of PL functions written in SQL.
8.3 introduced RETURN query which required a static sql statement, but did make things a bit easier.
&lt;/p&gt;

&lt;p&gt;One of the common use cases for using OUT parameters is to be able to return multiple outputs from a function without having
to declare a PostgreSQL type as output of the function.  In this article we shall cover all variants of this.  We&#039;ll just focus on sql and plpgsql for this
discussion, since we are not sure to what extent other pl languages (if at all) support IN OUT.&lt;/p&gt;
 &lt;br /&gt;&lt;a href=&quot;http://www.postgresonline.com/journal/archives/129-Use-of-OUT-and-INOUT-Parameters.html#extended&quot;&gt;Continue reading &quot;Use of OUT and INOUT Parameters&quot;&lt;/a&gt;
    </content:encoded>

    <pubDate>Thu, 30 Jul 2009 14:34:00 -0400</pubDate>
    <guid isPermaLink="false">http://www.postgresonline.com/journal/archives/129-guid.html</guid>
    
</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>
<item>
    <title>PostgreSQL 8.4 Faster array building with array_agg</title>
    <link>http://www.postgresonline.com/journal/archives/126-PostgreSQL-8.4-Faster-array-building-with-array_agg.html</link>
            <category>8.4</category>
            <category>basics</category>
            <category>db2</category>
            <category>intermediate</category>
            <category>postgis</category>
    
    <comments>http://www.postgresonline.com/journal/archives/126-PostgreSQL-8.4-Faster-array-building-with-array_agg.html#comments</comments>
    <wfw:comment>http://www.postgresonline.com/journal/wfwcomment.php?cid=126</wfw:comment>

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

    <author>nospam@example.com (Leo Hsu and Regina Obe)</author>
    <content:encoded>
    &lt;p&gt;One of the very handy features introduced in PostgreSQL 8.4 is the new aggregate function called &lt;a href=&quot;http://www.postgresql.org/docs/8.4/interactive/functions-aggregate.html&quot; target=&quot;_blank&quot;&gt;&lt;b&gt;array_agg&lt;/b&gt;&lt;/a&gt; which is a companion function to the &lt;a href=&quot;http://www.postgresonline.com/journal/archives/125-PostgreSQL-8.4-unnest-and-generate_series.html&quot; target=&quot;_blank&quot;&gt;&lt;b&gt;unnest&lt;/b&gt;&lt;/a&gt; function we discussed earlier.  This
takes a set of elements similar to what COUNT, SUM etc do and builds an array out of them. This approach is faster than the old used array_append , array_accum since it does not rebuild the array on each iteration.
&lt;/p&gt;
&lt;p&gt;
Sadly it does not appear to be completely swappable with array_append as there does not seem to be a mechanism to use it to build your own custom aggregate functions that need to maintain the set of objects flowing thru the aggregate without venturing into C land.  &lt;a href=&quot;http://www.postgresonline.com/journal/archives/67-Build-Median-Aggregate-Function-in-SQL.html#c960&quot; target=&quot;_blank&quot;&gt;This we tried to do
in our median example&lt;/a&gt; but were unsuccessful.&lt;/p&gt;
&lt;p&gt;
In PostGIS 1.4 &lt;a href=&quot;http://www.cleverelephant.ca/cv.html&quot; target=&quot;_blank&quot;&gt;Paul&lt;/a&gt; borrowed some of this array_agg logic to make the
PostGIS spatial aggregates much much faster with large numbers of geometries. So collecting polygons or making a &lt;a href=&quot;http://blog.cleverelephant.ca/2009/01/must-faster-unions-in-postgis-14.html&quot; target=&quot;_blank&quot;&gt;line out of say 30,000 geometries which normally would have taken 2 minutes or more (just accumulating), got reduced to under 10 seconds in many cases&lt;/a&gt;.
That did require C code even when installed against PostgreSQL 8.4.  Though in PostGIS you reap the benefits as far as geometries go even
if you are running lower than 8.4.&lt;/p&gt;

&lt;p&gt;We had originally thought array_agg was a PostgreSQL only creation, but it turns out that array_agg is a function defined in the ANSI SQL:2008 specs and for one appears to exist in &lt;a href=&quot;http://publib.boulder.ibm.com/infocenter/db2luw/v9r5/index.jsp?topic=/com.ibm.db2.luw.sql.ref.doc/doc/r0050494.html&quot; target=&quot;_blank&quot;&gt;IBM DB2&lt;/a&gt; as well.  I don&#039;t think
Oracle or any other database supports it as of yet.&lt;/p&gt;


&lt;p&gt;As we had demonstrated in the other article, we shall demonstrate the olden days and what array_agg brings to the table to make your life easier. &lt;/p&gt;
 &lt;br /&gt;&lt;a href=&quot;http://www.postgresonline.com/journal/archives/126-PostgreSQL-8.4-Faster-array-building-with-array_agg.html#extended&quot;&gt;Continue reading &quot;PostgreSQL 8.4 Faster array building with array_agg&quot;&lt;/a&gt;
    </content:encoded>

    <pubDate>Mon, 13 Jul 2009 22:55:00 -0400</pubDate>
    <guid isPermaLink="false">http://www.postgresonline.com/journal/archives/126-guid.html</guid>
    
</item>
<item>
    <title>PostgreSQL 8.4 unnest and generate_series</title>
    <link>http://www.postgresonline.com/journal/archives/125-PostgreSQL-8.4-unnest-and-generate_series.html</link>
            <category>8.4</category>
            <category>basics</category>
            <category>intermediate</category>
    
    <comments>http://www.postgresonline.com/journal/archives/125-PostgreSQL-8.4-unnest-and-generate_series.html#comments</comments>
    <wfw:comment>http://www.postgresonline.com/journal/wfwcomment.php?cid=125</wfw:comment>

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

    <author>nospam@example.com (Leo Hsu and Regina Obe)</author>
    <content:encoded>
    &lt;p&gt;In this issue we shall be celebrating the arrival of PostgreSQL 8.4 by showcasing the new treats
that PostgreSQL 8.4 has to offer.  Although 8.4 has some nice big ticket items like Windowing Functions which we 
briefly covered numerous times and Common Table Expressions, it also has some small ticket items.  These small ticket items
while small, are perhaps more useful than even the big ticket ones because they are more commonly used constructs.&lt;/p&gt;

&lt;p&gt;In this article we shall introduce the new unnest() function which makes converting an array to a table like structure
not only easier, but much more efficient.  We will also be covering the new enhancements to our favorite function the 
generate_series().  &lt;/p&gt; &lt;br /&gt;&lt;a href=&quot;http://www.postgresonline.com/journal/archives/125-PostgreSQL-8.4-unnest-and-generate_series.html#extended&quot;&gt;Continue reading &quot;PostgreSQL 8.4 unnest and generate_series&quot;&lt;/a&gt;
    </content:encoded>

    <pubDate>Thu, 09 Jul 2009 14:42:00 -0400</pubDate>
    <guid isPermaLink="false">http://www.postgresonline.com/journal/archives/125-guid.html</guid>
    
</item>
<item>
    <title>Restore of functional indexes gotcha</title>
    <link>http://www.postgresonline.com/journal/archives/121-Restore-of-functional-indexes-gotcha.html</link>
            <category>intermediate</category>
            <category>q&amp;a</category>
    
    <comments>http://www.postgresonline.com/journal/archives/121-Restore-of-functional-indexes-gotcha.html#comments</comments>
    <wfw:comment>http://www.postgresonline.com/journal/wfwcomment.php?cid=121</wfw:comment>

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

    <author>nospam@example.com (Leo Hsu and Regina Obe)</author>
    <content:encoded>
    &lt;p&gt;
	This has been bugging me for a long time and I finally complained about it and Tom Lane kindly gave a reason for the problem and that its by design and not a bug.
&lt;/p&gt;
&lt;p&gt;So I thought I would post the situation here without getting into too many embarassing specifics in case others have suffered from a similar fate and can learn from this.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;The situation: &lt;/b&gt;&lt;br /&gt;
&lt;UL&gt;
	&lt;LI&gt;You create a function lets call it &lt;b&gt;myniftyfunc()&lt;/b&gt; in the public schema. &lt;/LI&gt;
	&lt;LI&gt;Then you create another function that depends on myniftyfunc(), lets call it &lt;b&gt;mysuperniftyfunc()&lt;/b&gt; also in public schema.&lt;/LI&gt;
	&lt;LI&gt;Then because your function is such a super nifty function, you decide to create a functional index with that super function on your table that sits in mysuperdata schema -  &lt;b&gt;mysuperdata.mysupertable&lt;/b&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;/p&gt;
&lt;p&gt;Your super nifty function is doing its thing; your table is happy; the planner is spitting out your queries lightning fast using the super nifty index on your super table;
The world is good.&lt;/p&gt;
&lt;p&gt;One day you decide to restore your nifty database backup and to your chagrin, your nifty index is not there.  The planner is no longer happily spitting out your queries lighting fast and everything has come to a painful crawl.
Your super nifty index is gone.  What happened to super nifty functional index?&lt;/p&gt;

&lt;p&gt;I have to admit that I&#039;m the type of person that assumes the public schema is always there and always in search_path and that my assumption is a flawed one.  After all the public schema is there by default on new databases for convenience,
but one can change it not to be in the search_path and in fact &lt;b&gt;pg_dump&lt;/b&gt; does just that.  So if everything you have is kept in public schema -- you don&#039;t run into this particular misfortune.  If however you have your functions in
public and your tables in different schemas, during restore -- the search path is changed to the schema being restored and your super functional indexes based on super functions that depend on other super functions fail because public is no longer in the search_path. &lt;/p&gt;
 &lt;br /&gt;&lt;a href=&quot;http://www.postgresonline.com/journal/archives/121-Restore-of-functional-indexes-gotcha.html#extended&quot;&gt;Continue reading &quot;Restore of functional indexes gotcha&quot;&lt;/a&gt;
    </content:encoded>

    <pubDate>Thu, 18 Jun 2009 23:04:00 -0400</pubDate>
    <guid isPermaLink="false">http://www.postgresonline.com/journal/archives/121-guid.html</guid>
    
</item>
<item>
    <title>Running totals and sums using PostgreSQL 8.4 Windowing functions</title>
    <link>http://www.postgresonline.com/journal/archives/119-Running-totals-and-sums-using-PostgreSQL-8.4-Windowing-functions.html</link>
            <category>basics</category>
            <category>db2</category>
            <category>intermediate</category>
            <category>oracle</category>
            <category>sql server</category>
            <category>window functions</category>
    
    <comments>http://www.postgresonline.com/journal/archives/119-Running-totals-and-sums-using-PostgreSQL-8.4-Windowing-functions.html#comments</comments>
    <wfw:comment>http://www.postgresonline.com/journal/wfwcomment.php?cid=119</wfw:comment>

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

    <author>nospam@example.com (Leo Hsu and Regina Obe)</author>
    <content:encoded>
    &lt;P&gt;One thing that is pretty neat about windowing functions in PostgreSQL 8.4 aside from built-in windowing functions (row_number(), rank(), lead(), lag(), dense_rank(), percent_rank(), cume_dist(), first_value, last_value, nth_value) as documented in the manual &lt;a href=&quot;http://developer.postgresql.org/pgdocs/postgres/functions-window.html&quot; target=&quot;_blank&quot;&gt;Windowing Functions&lt;/a&gt; is that you can use windows with most aggregate functions (built-in or custom defined) as well as define your own specific windowing functions.   In a later article, we&#039;ll demonstrate creating custom windowing functions.
&lt;/P&gt;

&lt;P&gt;In our &lt;A href=&quot;http://www.pgcon.org/2009/schedule/events/174.en.html&quot; target=&quot;_blank&quot;&gt;PGCon 2009 PostGIS presentation&lt;/a&gt; one of the last slides demonstrates using lead() and lag() windowing functions
to show a family&#039;s income level in the same record with the income levels of the next door neighbors in the fictitious town we created.  This is not terribly useful unless you live
in a somewhat dysfunctional neighborhood where everyone is concerned about how rich their neighbors are compared to themselves.  Our town was very dysfunctional but mostly geographically dysfunctional. We will have much more useful use cases of this as applied to GIS in our upcoming &lt;a href=&quot;http://www.manning.com/obe&quot; target=&quot;_blank&quot;&gt;PostGIS in Action&lt;/a&gt; book.&lt;/P&gt;

&lt;p&gt; Hitoshi Harada and David Fetter did a presentation of this in PGCon 2009 which sadly we missed since we were giving our own presentation.  
Check out the &lt;a href=&quot;http://hosting3.epresence.tv/fosslc/1/watch/130.aspx&quot; target=&quot;_blank&quot;&gt;PGCon2009 PostgreSQL 8.4 Windowing Functions Video&lt;/a&gt;.  Also check out the slides at &lt;a href=&quot;http://www.pgcon.org/2009/schedule/events/128.en.html&quot; target=&quot;_blank&quot;&gt;Introducing Windowing Functions&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;Those who have used SQL Server  2005+, Oracle or IBM DBII are probably familar or have run into examples of Windowing functions in those products.  Windowing in PostgreSQL 8.4 works more or less the same way.  In a prior article, &lt;a href=&quot;http://www.postgresonline.com/journal/archives/47-How-to-calculate-Running-Totals-and-Sums-in-SQL.html&quot; target=&quot;_blank&quot;&gt;we demonstrated how to return running totals and sums&lt;/a&gt; using rudimentary SQL. 
To precelebrate the eminent arrival of PostgreSQL 8.4 and the current  PostgreSQL 8.4 beta 2 release, we shall demonstrate the same exercise using the new ANSI SQL:2003 Windowing functionality built
into the upcoming PostgreSQL 8.4. &lt;/p&gt; &lt;br /&gt;&lt;a href=&quot;http://www.postgresonline.com/journal/archives/119-Running-totals-and-sums-using-PostgreSQL-8.4-Windowing-functions.html#extended&quot;&gt;Continue reading &quot;Running totals and sums using PostgreSQL 8.4 Windowing functions&quot;&lt;/a&gt;
    </content:encoded>

    <pubDate>Wed, 27 May 2009 17:01:00 -0400</pubDate>
    <guid isPermaLink="false">http://www.postgresonline.com/journal/archives/119-guid.html</guid>
    
</item>
<item>
    <title>Creating instance of custom type</title>
    <link>http://www.postgresonline.com/journal/archives/118-Creating-instance-of-custom-type.html</link>
            <category>8.2</category>
            <category>8.3</category>
            <category>8.4</category>
            <category>intermediate</category>
            <category>postgis</category>
            <category>postgresql versions</category>
            <category>q&amp;a</category>
    
    <comments>http://www.postgresonline.com/journal/archives/118-Creating-instance-of-custom-type.html#comments</comments>
    <wfw:comment>http://www.postgresonline.com/journal/wfwcomment.php?cid=118</wfw:comment>

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

    <author>nospam@example.com (Leo Hsu and Regina Obe)</author>
    <content:encoded>
    &lt;p&gt;Someone asked me this recently and not playing with custom types much, I&#039;m not sure this is 
the best solution.  Anyrate here it goes. Note this works for PostgreSQL 8.2 and above.  Note sure about 8.1 etc.
I assume it probably does.&lt;/p&gt;

&lt;p&gt;Let us say you created a custom type something like this: &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&lt;span class=&quot;syntax0&quot;&gt;&lt;span class=&quot;syntax8&quot;&gt;CREATE&lt;/span&gt; TYPE my_type1 &lt;span class=&quot;syntax8&quot;&gt;AS&lt;/span&gt;
   &lt;span class=&quot;syntax18&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;syntax8&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;syntax8&quot;&gt;varchar&lt;/span&gt;&lt;span class=&quot;syntax18&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;syntax5&quot;&gt;150&lt;/span&gt;&lt;span class=&quot;syntax18&quot;&gt;)&lt;/span&gt;,
    rotation_x &lt;span class=&quot;syntax8&quot;&gt;double&lt;/span&gt; &lt;span class=&quot;syntax8&quot;&gt;precision&lt;/span&gt;,
    rotation_y &lt;span class=&quot;syntax8&quot;&gt;double&lt;/span&gt; &lt;span class=&quot;syntax8&quot;&gt;precision&lt;/span&gt;,
    x_pos &lt;span class=&quot;syntax8&quot;&gt;integer&lt;/span&gt;,
    y_pos &lt;span class=&quot;syntax8&quot;&gt;integer&lt;/span&gt;
    &lt;span class=&quot;syntax18&quot;&gt;)&lt;/span&gt;;
    
&lt;/span&gt;
&lt;/code&gt;	
&lt;/pre&gt;	 &lt;br /&gt;&lt;a href=&quot;http://www.postgresonline.com/journal/archives/118-Creating-instance-of-custom-type.html#extended&quot;&gt;Continue reading &quot;Creating instance of custom type&quot;&lt;/a&gt;
    </content:encoded>

    <pubDate>Thu, 21 May 2009 04:54:00 -0400</pubDate>
    <guid isPermaLink="false">http://www.postgresonline.com/journal/archives/118-guid.html</guid>
    
</item>

</channel>
</rss>