<?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 aggregates)</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>Wed, 25 Jan 2012 21:01:44 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>True or False every which way</title>
    <link>http://www.postgresonline.com/journal/archives/241-True-or-False-every-which-way.html</link>
            <category>intermediate</category>
            <category>q&amp;a</category>
    
    <comments>http://www.postgresonline.com/journal/archives/241-True-or-False-every-which-way.html#comments</comments>
    <wfw:comment>http://www.postgresonline.com/journal/wfwcomment.php?cid=241</wfw:comment>

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

    <author>nospam@example.com (Leo Hsu and Regina Obe)</author>
    <content:encoded>
    &lt;p&gt;PostgreSQL has aggregate functions called &lt;b&gt;bool_and&lt;/b&gt; and &lt;b&gt;bool_or&lt;/b&gt; which it&#039;s had for as far back as I can remember.
What do they do? given rows of premises (things that resolve to booleans), &lt;em&gt;bool_and&lt;/em&gt; will return true if all of the premises are true.  Similarly &lt;b&gt;bool_or&lt;/b&gt;
will return true if any of the premises in the set of rows is true.  What if however your boolean expressions are not in rows, but instead passed in
as a sequence of arbitrary statements of questionable fact.  We want a function like bool_or or bool_and that takes an arbitrary number of boolean arguments.  Are there functions
that fit the bill.  Indeed there are, but they don&#039;t scream out and say &lt;em&gt;I work with booleans&lt;/em&gt; because they fit into a class of function we
discussed in &lt;a href=&quot;http://www.postgresonline.com/journal/archives/239-The-wonders-of-Any-Element.html&quot; target=&quot;_blank&quot;&gt;The wonders of Any Element&lt;/a&gt; and that also happen to be &lt;a href=&quot;http://www.postgresonline.com/journal/archives/211-Variadic-Functions-in-PostgreSQL.html&quot; target=&quot;_blank&quot;&gt;variadic&lt;/a&gt; functions.
These are none other than
&lt;b&gt;greatest&lt;/b&gt; and &lt;b&gt;least&lt;/b&gt; and they are old timer functions that you can find in most versions of PostgreSQL.  We&#039;ll demonstrate how to use
all 4 with booleans in this article. It must be said that greatest and least are much more useful when applied to other data types like dates
and numbers, but we were amused at the parallel with booleans.&lt;/p&gt;

&lt;div style=&#039;background-color:yellow&#039;&gt;&lt;b&gt;Side note:&lt;/b&gt; we&#039;ve started to write our book on PostgreSQL that will be published by O&#039;Reilly.  We hope to finish this book within the next 5-7 months but have preliminary e-Book drafts before then for early purchasers to scan.
The focus of the book will be PostgreSQL 9.1 with some highlights the upcoming PostgreSQL 9.2.  Of course oldie but goodie topics are  in the book too. It&#039;s a thrill to be writing again.&lt;/div&gt; &lt;br /&gt;&lt;a href=&quot;http://www.postgresonline.com/journal/archives/241-True-or-False-every-which-way.html#extended&quot;&gt;Continue reading &quot;True or False every which way&quot;&lt;/a&gt;
    </content:encoded>

    <pubDate>Wed, 25 Jan 2012 15:55:00 -0500</pubDate>
    <guid isPermaLink="false">http://www.postgresonline.com/journal/archives/241-guid.html</guid>
    <category>aggregates</category>
<category>anyelement</category>
<category>bool_and</category>
<category>bool_or</category>
<category>greatst</category>
<category>least</category>

</item>
<item>
    <title>How to create an n-column table really fast</title>
    <link>http://www.postgresonline.com/journal/archives/230-How-to-create-an-n-column-table-really-fast.html</link>
            <category>8.4</category>
            <category>9.0</category>
            <category>9.1</category>
            <category>9.2</category>
            <category>beginner</category>
            <category>postgresql versions</category>
            <category>q&amp;a</category>
    
    <comments>http://www.postgresonline.com/journal/archives/230-How-to-create-an-n-column-table-really-fast.html#comments</comments>
    <wfw:comment>http://www.postgresonline.com/journal/wfwcomment.php?cid=230</wfw:comment>

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

    <author>nospam@example.com (Leo Hsu and Regina Obe)</author>
    <content:encoded>
    &lt;p&gt;Ever have the need to create a holding table say spreadsheet data with say 100 columns. You need to create a table to hold this stuff.   Or perhaps you were feeling in a sadist mood and wanted to abuse your PostgreSQL database to see how many columns you can create in a table of a specific data type. 
Here is a quick script to do it:&lt;/p&gt;

&lt;code&gt;
&lt;pre&gt;&lt;span class=&quot;syntax0&quot;&gt;&lt;span class=&quot;syntax-COMMENT1&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;syntax-COMMENT1&quot;&gt; &lt;/span&gt;&lt;span class=&quot;syntax-COMMENT1&quot;&gt;8.4+&lt;/span&gt;&lt;span class=&quot;syntax-COMMENT1&quot;&gt; &lt;/span&gt;&lt;span class=&quot;syntax-COMMENT1&quot;&gt;syntax&lt;/span&gt;
&lt;span class=&quot;syntax-KEYWORD1&quot;&gt;SELECT&lt;/span&gt; &lt;span class=&quot;syntax-LITERAL1&quot;&gt;&#039;&lt;/span&gt;&lt;span class=&quot;syntax-LITERAL1&quot;&gt;CREATE&lt;/span&gt;&lt;span class=&quot;syntax-LITERAL1&quot;&gt; &lt;/span&gt;&lt;span class=&quot;syntax-LITERAL1&quot;&gt;TABLE&lt;/span&gt;&lt;span class=&quot;syntax-LITERAL1&quot;&gt; &lt;/span&gt;&lt;span class=&quot;syntax-LITERAL1&quot;&gt;data_import(&lt;/span&gt;&lt;span class=&quot;syntax-LITERAL1&quot;&gt;&#039;&lt;/span&gt;
&lt;span class=&quot;syntax-OPERATOR&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;syntax-OPERATOR&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;syntax-FUNCTION&quot;&gt;array_to_string&lt;/span&gt;&lt;span class=&quot;syntax-OPERATOR&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;syntax-FUNCTION&quot;&gt;array_agg&lt;/span&gt;&lt;span class=&quot;syntax-OPERATOR&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;syntax-LITERAL1&quot;&gt;&#039;&lt;/span&gt;&lt;span class=&quot;syntax-LITERAL1&quot;&gt;field&lt;/span&gt;&lt;span class=&quot;syntax-LITERAL1&quot;&gt;&#039;&lt;/span&gt; &lt;span class=&quot;syntax-OPERATOR&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;syntax-OPERATOR&quot;&gt;|&lt;/span&gt; i&lt;span class=&quot;syntax-OPERATOR&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;syntax-KEYWORD1&quot;&gt;text&lt;/span&gt; &lt;span class=&quot;syntax-OPERATOR&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;syntax-OPERATOR&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;syntax-LITERAL1&quot;&gt;&#039;&lt;/span&gt;&lt;span class=&quot;syntax-LITERAL1&quot;&gt; &lt;/span&gt;&lt;span class=&quot;syntax-LITERAL1&quot;&gt;varchar(255)&lt;/span&gt;&lt;span class=&quot;syntax-LITERAL1&quot;&gt;&#039;&lt;/span&gt;&lt;span class=&quot;syntax-OPERATOR&quot;&gt;)&lt;/span&gt;, &lt;span class=&quot;syntax-LITERAL1&quot;&gt;&#039;&lt;/span&gt;&lt;span class=&quot;syntax-LITERAL1&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;syntax-LITERAL1&quot;&gt;&#039;&lt;/span&gt;&lt;span class=&quot;syntax-OPERATOR&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;syntax-OPERATOR&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;syntax-OPERATOR&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;syntax-LITERAL1&quot;&gt;&#039;&lt;/span&gt;&lt;span class=&quot;syntax-LITERAL1&quot;&gt;);&lt;/span&gt;&lt;span class=&quot;syntax-LITERAL1&quot;&gt;&#039;&lt;/span&gt;
&lt;span class=&quot;syntax-KEYWORD1&quot;&gt;FROM&lt;/span&gt; &lt;span class=&quot;syntax-FUNCTION&quot;&gt;generate_series&lt;/span&gt;&lt;span class=&quot;syntax-OPERATOR&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;syntax-DIGIT&quot;&gt;1&lt;/span&gt;,&lt;span class=&quot;syntax-DIGIT&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;syntax-OPERATOR&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;syntax-KEYWORD1&quot;&gt;As&lt;/span&gt; i;

&lt;span class=&quot;syntax-COMMENT1&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;syntax-COMMENT1&quot;&gt; &lt;/span&gt;&lt;span class=&quot;syntax-COMMENT1&quot;&gt;9.0+&lt;/span&gt;&lt;span class=&quot;syntax-COMMENT1&quot;&gt; &lt;/span&gt;&lt;span class=&quot;syntax-COMMENT1&quot;&gt;syntax&lt;/span&gt;&lt;span class=&quot;syntax-COMMENT1&quot;&gt; &lt;/span&gt;&lt;span class=&quot;syntax-COMMENT1&quot;&gt;(string_agg&lt;/span&gt;&lt;span class=&quot;syntax-COMMENT1&quot;&gt; &lt;/span&gt;&lt;span class=&quot;syntax-COMMENT1&quot;&gt;was&lt;/span&gt;&lt;span class=&quot;syntax-COMMENT1&quot;&gt; &lt;/span&gt;&lt;span class=&quot;syntax-COMMENT1&quot;&gt;introduced&lt;/span&gt;&lt;span class=&quot;syntax-COMMENT1&quot;&gt; &lt;/span&gt;&lt;span class=&quot;syntax-COMMENT1&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;syntax-COMMENT1&quot;&gt; &lt;/span&gt;&lt;span class=&quot;syntax-COMMENT1&quot;&gt;9.0)&lt;/span&gt;
&lt;span class=&quot;syntax-KEYWORD1&quot;&gt;SELECT&lt;/span&gt; &lt;span class=&quot;syntax-LITERAL1&quot;&gt;&#039;&lt;/span&gt;&lt;span class=&quot;syntax-LITERAL1&quot;&gt;CREATE&lt;/span&gt;&lt;span class=&quot;syntax-LITERAL1&quot;&gt; &lt;/span&gt;&lt;span class=&quot;syntax-LITERAL1&quot;&gt;TABLE&lt;/span&gt;&lt;span class=&quot;syntax-LITERAL1&quot;&gt; &lt;/span&gt;&lt;span class=&quot;syntax-LITERAL1&quot;&gt;data_import(&lt;/span&gt;&lt;span class=&quot;syntax-LITERAL1&quot;&gt;&#039;&lt;/span&gt;
&lt;span class=&quot;syntax-OPERATOR&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;syntax-OPERATOR&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;syntax-FUNCTION&quot;&gt;string_agg&lt;/span&gt;&lt;span class=&quot;syntax-OPERATOR&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;syntax-LITERAL1&quot;&gt;&#039;&lt;/span&gt;&lt;span class=&quot;syntax-LITERAL1&quot;&gt;field&lt;/span&gt;&lt;span class=&quot;syntax-LITERAL1&quot;&gt;&#039;&lt;/span&gt; &lt;span class=&quot;syntax-OPERATOR&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;syntax-OPERATOR&quot;&gt;|&lt;/span&gt; i&lt;span class=&quot;syntax-OPERATOR&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;syntax-KEYWORD1&quot;&gt;text&lt;/span&gt; &lt;span class=&quot;syntax-OPERATOR&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;syntax-OPERATOR&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;syntax-LITERAL1&quot;&gt;&#039;&lt;/span&gt;&lt;span class=&quot;syntax-LITERAL1&quot;&gt; &lt;/span&gt;&lt;span class=&quot;syntax-LITERAL1&quot;&gt;varchar(255)&lt;/span&gt;&lt;span class=&quot;syntax-LITERAL1&quot;&gt;&#039;&lt;/span&gt;, &lt;span class=&quot;syntax-LITERAL1&quot;&gt;&#039;&lt;/span&gt;&lt;span class=&quot;syntax-LITERAL1&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;syntax-LITERAL1&quot;&gt;&#039;&lt;/span&gt;&lt;span class=&quot;syntax-OPERATOR&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;syntax-OPERATOR&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;syntax-OPERATOR&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;syntax-LITERAL1&quot;&gt;&#039;&lt;/span&gt;&lt;span class=&quot;syntax-LITERAL1&quot;&gt;);&lt;/span&gt;&lt;span class=&quot;syntax-LITERAL1&quot;&gt;&#039;&lt;/span&gt;
&lt;span class=&quot;syntax-KEYWORD1&quot;&gt;FROM&lt;/span&gt; &lt;span class=&quot;syntax-FUNCTION&quot;&gt;generate_series&lt;/span&gt;&lt;span class=&quot;syntax-OPERATOR&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;syntax-DIGIT&quot;&gt;1&lt;/span&gt;,&lt;span class=&quot;syntax-DIGIT&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;syntax-OPERATOR&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;syntax-KEYWORD1&quot;&gt;As&lt;/span&gt; i;
&lt;/span&gt;&lt;/pre&gt;&lt;/code&gt;

&lt;p&gt;Both variants will return output that looks like this: &lt;/p&gt;
&lt;pre&gt;&lt;span class=&quot;syntax0&quot;&gt;&lt;span class=&quot;syntax-KEYWORD1&quot;&gt;CREATE&lt;/span&gt; &lt;span class=&quot;syntax-KEYWORD1&quot;&gt;TABLE&lt;/span&gt; &lt;span class=&quot;syntax-FUNCTION&quot;&gt;data_import&lt;/span&gt;&lt;span class=&quot;syntax-OPERATOR&quot;&gt;(&lt;/span&gt;field1 &lt;span class=&quot;syntax-KEYWORD1&quot;&gt;varchar&lt;/span&gt;&lt;span class=&quot;syntax-OPERATOR&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;syntax-DIGIT&quot;&gt;255&lt;/span&gt;&lt;span class=&quot;syntax-OPERATOR&quot;&gt;)&lt;/span&gt;,field2 &lt;span class=&quot;syntax-KEYWORD1&quot;&gt;varchar&lt;/span&gt;&lt;span class=&quot;syntax-OPERATOR&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;syntax-DIGIT&quot;&gt;255&lt;/span&gt;&lt;span class=&quot;syntax-OPERATOR&quot;&gt;)&lt;/span&gt;,field3 &lt;span class=&quot;syntax-KEYWORD1&quot;&gt;varchar&lt;/span&gt;&lt;span class=&quot;syntax-OPERATOR&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;syntax-DIGIT&quot;&gt;255&lt;/span&gt;&lt;span class=&quot;syntax-OPERATOR&quot;&gt;)&lt;/span&gt;,field4 &lt;span class=&quot;syntax-KEYWORD1&quot;&gt;varchar&lt;/span&gt;&lt;span class=&quot;syntax-OPERATOR&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;syntax-DIGIT&quot;&gt;255&lt;/span&gt;&lt;span class=&quot;syntax-OPERATOR&quot;&gt;)&lt;/span&gt;
    ,field5 &lt;span class=&quot;syntax-KEYWORD1&quot;&gt;varchar&lt;/span&gt;&lt;span class=&quot;syntax-OPERATOR&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;syntax-DIGIT&quot;&gt;255&lt;/span&gt;&lt;span class=&quot;syntax-OPERATOR&quot;&gt;)&lt;/span&gt;,field6 &lt;span class=&quot;syntax-KEYWORD1&quot;&gt;varchar&lt;/span&gt;&lt;span class=&quot;syntax-OPERATOR&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;syntax-DIGIT&quot;&gt;255&lt;/span&gt;&lt;span class=&quot;syntax-OPERATOR&quot;&gt;)&lt;/span&gt;,field7 &lt;span class=&quot;syntax-KEYWORD1&quot;&gt;varchar&lt;/span&gt;&lt;span class=&quot;syntax-OPERATOR&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;syntax-DIGIT&quot;&gt;255&lt;/span&gt;&lt;span class=&quot;syntax-OPERATOR&quot;&gt;)&lt;/span&gt;
    ,field8 &lt;span class=&quot;syntax-KEYWORD1&quot;&gt;varchar&lt;/span&gt;&lt;span class=&quot;syntax-OPERATOR&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;syntax-DIGIT&quot;&gt;255&lt;/span&gt;&lt;span class=&quot;syntax-OPERATOR&quot;&gt;)&lt;/span&gt;,field9 &lt;span class=&quot;syntax-KEYWORD1&quot;&gt;varchar&lt;/span&gt;&lt;span class=&quot;syntax-OPERATOR&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;syntax-DIGIT&quot;&gt;255&lt;/span&gt;&lt;span class=&quot;syntax-OPERATOR&quot;&gt;)&lt;/span&gt;,field10 &lt;span class=&quot;syntax-KEYWORD1&quot;&gt;varchar&lt;/span&gt;&lt;span class=&quot;syntax-OPERATOR&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;syntax-DIGIT&quot;&gt;255&lt;/span&gt;&lt;span class=&quot;syntax-OPERATOR&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;syntax-OPERATOR&quot;&gt;)&lt;/span&gt;;
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Now if you want it to also execute because you are running it as part of an sql script, you could wrap it in an anonymous function.&lt;/p&gt;
&lt;code&gt;
&lt;pre&gt;&lt;span class=&quot;syntax0&quot;&gt; &lt;span class=&quot;syntax-COMMENT1&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;syntax-COMMENT1&quot;&gt;-wrap&lt;/span&gt;&lt;span class=&quot;syntax-COMMENT1&quot;&gt; &lt;/span&gt;&lt;span class=&quot;syntax-COMMENT1&quot;&gt;it&lt;/span&gt;&lt;span class=&quot;syntax-COMMENT1&quot;&gt; &lt;/span&gt;&lt;span class=&quot;syntax-COMMENT1&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;syntax-COMMENT1&quot;&gt; &lt;/span&gt;&lt;span class=&quot;syntax-COMMENT1&quot;&gt;an&lt;/span&gt;&lt;span class=&quot;syntax-COMMENT1&quot;&gt; &lt;/span&gt;&lt;span class=&quot;syntax-COMMENT1&quot;&gt;anonymous&lt;/span&gt;&lt;span class=&quot;syntax-COMMENT1&quot;&gt; &lt;/span&gt;&lt;span class=&quot;syntax-COMMENT1&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;syntax-COMMENT1&quot;&gt; &lt;/span&gt;&lt;span class=&quot;syntax-COMMENT1&quot;&gt;to&lt;/span&gt;&lt;span class=&quot;syntax-COMMENT1&quot;&gt; &lt;/span&gt;&lt;span class=&quot;syntax-COMMENT1&quot;&gt;run&lt;/span&gt;
 &lt;span class=&quot;syntax-COMMENT1&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;syntax-COMMENT1&quot;&gt; &lt;/span&gt;&lt;span class=&quot;syntax-COMMENT1&quot;&gt;requires&lt;/span&gt;&lt;span class=&quot;syntax-COMMENT1&quot;&gt; &lt;/span&gt;&lt;span class=&quot;syntax-COMMENT1&quot;&gt;PostgreSQL&lt;/span&gt;&lt;span class=&quot;syntax-COMMENT1&quot;&gt; &lt;/span&gt;&lt;span class=&quot;syntax-COMMENT1&quot;&gt;9.0+&lt;/span&gt;
DO language &lt;span class=&quot;syntax-LITERAL1&quot;&gt;&#039;&lt;/span&gt;&lt;span class=&quot;syntax-LITERAL1&quot;&gt;plpgsql&lt;/span&gt;&lt;span class=&quot;syntax-LITERAL1&quot;&gt;&#039;&lt;/span&gt;
$$
&lt;span class=&quot;syntax-KEYWORD1&quot;&gt;DECLARE&lt;/span&gt; var_sql &lt;span class=&quot;syntax-KEYWORD1&quot;&gt;text&lt;/span&gt; :&lt;span class=&quot;syntax-OPERATOR&quot;&gt;=&lt;/span&gt;  &lt;span class=&quot;syntax-LITERAL1&quot;&gt;&#039;&lt;/span&gt;&lt;span class=&quot;syntax-LITERAL1&quot;&gt;CREATE&lt;/span&gt;&lt;span class=&quot;syntax-LITERAL1&quot;&gt; &lt;/span&gt;&lt;span class=&quot;syntax-LITERAL1&quot;&gt;TABLE&lt;/span&gt;&lt;span class=&quot;syntax-LITERAL1&quot;&gt; &lt;/span&gt;&lt;span class=&quot;syntax-LITERAL1&quot;&gt;data_import(&lt;/span&gt;&lt;span class=&quot;syntax-LITERAL1&quot;&gt;&#039;&lt;/span&gt;
    &lt;span class=&quot;syntax-OPERATOR&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;syntax-OPERATOR&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;syntax-FUNCTION&quot;&gt;string_agg&lt;/span&gt;&lt;span class=&quot;syntax-OPERATOR&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;syntax-LITERAL1&quot;&gt;&#039;&lt;/span&gt;&lt;span class=&quot;syntax-LITERAL1&quot;&gt;field&lt;/span&gt;&lt;span class=&quot;syntax-LITERAL1&quot;&gt;&#039;&lt;/span&gt; &lt;span class=&quot;syntax-OPERATOR&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;syntax-OPERATOR&quot;&gt;|&lt;/span&gt; i&lt;span class=&quot;syntax-OPERATOR&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;syntax-KEYWORD1&quot;&gt;text&lt;/span&gt; &lt;span class=&quot;syntax-OPERATOR&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;syntax-OPERATOR&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;syntax-LITERAL1&quot;&gt;&#039;&lt;/span&gt;&lt;span class=&quot;syntax-LITERAL1&quot;&gt; &lt;/span&gt;&lt;span class=&quot;syntax-LITERAL1&quot;&gt;varchar(255)&lt;/span&gt;&lt;span class=&quot;syntax-LITERAL1&quot;&gt;&#039;&lt;/span&gt;, &lt;span class=&quot;syntax-LITERAL1&quot;&gt;&#039;&lt;/span&gt;&lt;span class=&quot;syntax-LITERAL1&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;syntax-LITERAL1&quot;&gt;&#039;&lt;/span&gt;&lt;span class=&quot;syntax-OPERATOR&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;syntax-OPERATOR&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;syntax-OPERATOR&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;syntax-LITERAL1&quot;&gt;&#039;&lt;/span&gt;&lt;span class=&quot;syntax-LITERAL1&quot;&gt;);&lt;/span&gt;&lt;span class=&quot;syntax-LITERAL1&quot;&gt;&#039;&lt;/span&gt;
    &lt;span class=&quot;syntax-KEYWORD1&quot;&gt;FROM&lt;/span&gt; &lt;span class=&quot;syntax-FUNCTION&quot;&gt;generate_series&lt;/span&gt;&lt;span class=&quot;syntax-OPERATOR&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;syntax-DIGIT&quot;&gt;1&lt;/span&gt;,&lt;span class=&quot;syntax-DIGIT&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;syntax-OPERATOR&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;syntax-KEYWORD1&quot;&gt;As&lt;/span&gt; i;
&lt;span class=&quot;syntax-KEYWORD1&quot;&gt;BEGIN&lt;/span&gt;
    &lt;span class=&quot;syntax-KEYWORD1&quot;&gt;EXECUTE&lt;/span&gt; var_sql;
&lt;span class=&quot;syntax-KEYWORD1&quot;&gt;END&lt;/span&gt;;
$$ ;
&lt;/span&gt;&lt;/pre&gt;&lt;/code&gt;
 
    </content:encoded>

    <pubDate>Tue, 01 Nov 2011 22:31:00 -0400</pubDate>
    <guid isPermaLink="false">http://www.postgresonline.com/journal/archives/230-guid.html</guid>
    <category>aggregates</category>
<category>array</category>
<category>array_agg</category>
<category>string_agg</category>

</item>
<item>
    <title>PostgreSQL Array: The ANY and Contains trick</title>
    <link>http://www.postgresonline.com/journal/archives/228-PostgreSQL-Array-The-ANY-and-Contains-trick.html</link>
            <category>intermediate</category>
            <category>q&amp;a</category>
    
    <comments>http://www.postgresonline.com/journal/archives/228-PostgreSQL-Array-The-ANY-and-Contains-trick.html#comments</comments>
    <wfw:comment>http://www.postgresonline.com/journal/wfwcomment.php?cid=228</wfw:comment>

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

    <author>nospam@example.com (Leo Hsu and Regina Obe)</author>
    <content:encoded>
    &lt;p&gt;One of the main features I love about PostgreSQL is its array support.  This is a 
feature you won&#039;t find in most relational databases, and even databases that support some variant
of it, don&#039;t allow you to use it as easily.  It is one of the features that makes building
aggregate functions wicked easy in PostgreSQL with no messy compiling required.  
Aside from building aggregate functions, it has some other common day uses.  
In this article, I&#039;ll cover two common ways we use them which I will refer to as the &lt;b&gt;ANY&lt;/b&gt;
and &lt;b&gt;Contains&lt;/b&gt; tricks.&lt;/p&gt;

&lt;p&gt;I like to think of this approach as &lt;a href=&quot;http://blog.gigaspaces.com/2010/07/15/yesql-an-overview-of-the-various-query-semantics-in-the-post-only-sql-world/&quot; target=&quot;_blank&quot;&gt;YeSQL programming style&lt;/a&gt;: how SQL can be augmented by more complex data types and index retrieval mechanisms.
 Arrays and many other data types (spatial types, keyvalue (hstore), ltree etc) are far from relational structures, yet we can query them easily with SQL and can even relate them.&lt;/p&gt; &lt;br /&gt;&lt;a href=&quot;http://www.postgresonline.com/journal/archives/228-PostgreSQL-Array-The-ANY-and-Contains-trick.html#extended&quot;&gt;Continue reading &quot;PostgreSQL Array: The ANY and Contains trick&quot;&lt;/a&gt;
    </content:encoded>

    <pubDate>Thu, 27 Oct 2011 01:09:00 -0400</pubDate>
    <guid isPermaLink="false">http://www.postgresonline.com/journal/archives/228-guid.html</guid>
    <category>aggregates</category>
<category>all</category>
<category>array</category>
<category>string_agg</category>
<category>yesql</category>

</item>
<item>
    <title>PLPython Part 5: PLPython meets PostgreSQL Multi-column aggregates and SVG plots</title>
    <link>http://www.postgresonline.com/journal/archives/107-PLPython-Part-5-PLPython-meets-PostgreSQL-Multi-column-aggregates-and-SVG-plots.html</link>
            <category>8.2</category>
            <category>8.3</category>
            <category>8.4</category>
            <category>advanced</category>
            <category>pl programming</category>
            <category>plpython</category>
            <category>postgresql versions</category>
    
    <comments>http://www.postgresonline.com/journal/archives/107-PLPython-Part-5-PLPython-meets-PostgreSQL-Multi-column-aggregates-and-SVG-plots.html#comments</comments>
    <wfw:comment>http://www.postgresonline.com/journal/wfwcomment.php?cid=107</wfw:comment>

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

    <author>nospam@example.com (Leo Hsu and Regina Obe)</author>
    <content:encoded>
    &lt;p&gt;In our &lt;a href=&quot;http://www.postgresonline.com/journal/archives/102-PLPython-Part-4-PLPython-meets-aggregates.html&quot; target=&quot;_blank&quot;&gt;PLPython Part 4: PLPython meets aggregates&lt;/a&gt; we demonstrated the power of PostgreSQL  in combination
with PLPython to create a sequence of ascii plots by using the power of aggregation.  Our friend &lt;a href=&quot;http://www.spatialdbadvisor.com/&quot; target=&quot;_blank&quot;&gt;Simon Greener over at Spatial Db Advisor&lt;/a&gt; told me the example
was clever but ascii plots was so 70ish and ugly, why didn&#039;t I do SVG plots? He felt people being predominantly visual would be caught up in the ugliness of Ascii plots and miss the point.
At least &lt;a href=&quot;http://www.postgresonline.com/journal/archives/102-PLPython-Part-4-PLPython-meets-aggregates.html#c803&quot; target&quot;_blank&quot;&gt;Bob found them neat and can appreciate the elegance in simplicity, thanks Bob.&lt;/a&gt;.

&lt;p&gt;
To make it up
to Simon, we shall demonstrate 2 features we left out in our prior article.
&lt;/p&gt;
&lt;p&gt;
&lt;OL&gt;&lt;LI&gt;Pretty SVG graphs -- so I don&#039;t have to hear more about SVG from Simon and how I&#039;m caught in the 70s.&lt;/LI&gt;
	&lt;LI&gt;Ability to plot a schedule -- schedule item, start date, end date using a multi-column aggregate function. Here is a good use for multi-column aggregates or at least I think so. (Yeh for Multi-column aggregates)&lt;/LI&gt;
&lt;/OL&gt;
&lt;/p&gt;

&lt;p&gt;If you are into spatial processing in the database or how many ways you can play with XML particularly &lt;a href=&quot;http://www.spatialdbadvisor.com/oracle_spatial_tips_tricks&quot; target=&quot;_blank&quot;&gt;Oracle Locator, Oracle Spatial&lt;/a&gt;, &lt;a href=&quot;http://www.spatialdbadvisor.com/postgis_tips_tricks&quot; target=&quot;_blank&quot;&gt;PostGIS&lt;/a&gt; and &lt;a href=&quot;http://www.spatialdbadvisor.com/sql_server_blog&quot; target=&quot;_blank&quot;&gt;SQL Server 2008&lt;/a&gt;, we highly recommend &lt;a href=&quot;http://www.spatialdbadvisor.com/&quot; target=&quot;_blank&quot;&gt;Simon&#039;s articles&lt;/a&gt;.&lt;/p&gt;
 &lt;br /&gt;&lt;a href=&quot;http://www.postgresonline.com/journal/archives/107-PLPython-Part-5-PLPython-meets-PostgreSQL-Multi-column-aggregates-and-SVG-plots.html#extended&quot;&gt;Continue reading &quot;PLPython Part 5: PLPython meets PostgreSQL Multi-column aggregates and SVG plots&quot;&lt;/a&gt;
    </content:encoded>

    <pubDate>Fri, 13 Mar 2009 08:28:00 -0400</pubDate>
    <guid isPermaLink="false">http://www.postgresonline.com/journal/archives/107-guid.html</guid>
    <category>aggregates</category>
<category>plpython</category>

</item>
<item>
    <title>PLPython Part 4: PLPython meets aggregates</title>
    <link>http://www.postgresonline.com/journal/archives/102-PLPython-Part-4-PLPython-meets-aggregates.html</link>
            <category>8.2</category>
            <category>8.3</category>
            <category>8.4</category>
            <category>intermediate</category>
            <category>pl programming</category>
            <category>plpython</category>
    
    <comments>http://www.postgresonline.com/journal/archives/102-PLPython-Part-4-PLPython-meets-aggregates.html#comments</comments>
    <wfw:comment>http://www.postgresonline.com/journal/wfwcomment.php?cid=102</wfw:comment>

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

    <author>nospam@example.com (Leo Hsu and Regina Obe)</author>
    <content:encoded>
    &lt;p&gt;In our &lt;a href=&quot;/index.php?i_id=7&quot; target=&quot;_blank&quot;&gt;August 2008/ September 2008 issue&lt;/a&gt; we demonstrated the power of PostgreSQL to create median and MS Access-like first and last aggregate functions in
SQL language.  In this article we shall demonstrate how to create aggregates with Python.  We shall
call this function &lt;b&gt;agg_plot&lt;/b&gt;.  What it will do is plot each grouping of data and return a plot for each grouping. The steps
we covered in those articles can be applied here.&lt;/p&gt;

&lt;p&gt;For this part, we shall use the same library we discussed in &lt;a href=&quot;http://www.postgresonline.com/journal/archives/101-PLPython-Part-3-Using-custom-classes,-pulling-data-from-PostgreSQL.html&quot; target=&quot;_blank&quot;&gt;PLPython Part 3: Using custom classes, pulling data from PostgreSQL&lt;/a&gt;.&lt;/p&gt;
 &lt;br /&gt;&lt;a href=&quot;http://www.postgresonline.com/journal/archives/102-PLPython-Part-4-PLPython-meets-aggregates.html#extended&quot;&gt;Continue reading &quot;PLPython Part 4: PLPython meets aggregates&quot;&lt;/a&gt;
    </content:encoded>

    <pubDate>Thu, 05 Feb 2009 19:36:00 -0500</pubDate>
    <guid isPermaLink="false">http://www.postgresonline.com/journal/archives/102-guid.html</guid>
    <category>aggregates</category>
<category>plpython</category>

</item>
<item>
    <title>More Aggregate Fun: Who's on First and Who's on Last</title>
    <link>http://www.postgresonline.com/journal/archives/68-More-Aggregate-Fun-Whos-on-First-and-Whos-on-Last.html</link>
            <category>intermediate</category>
            <category>ms access</category>
            <category>mysql</category>
            <category>pl programming</category>
            <category>sql functions</category>
            <category>sql server</category>
    
    <comments>http://www.postgresonline.com/journal/archives/68-More-Aggregate-Fun-Whos-on-First-and-Whos-on-Last.html#comments</comments>
    <wfw:comment>http://www.postgresonline.com/journal/wfwcomment.php?cid=68</wfw:comment>

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

    <author>nospam@example.com (Leo Hsu and Regina Obe)</author>
    <content:encoded>
    &lt;P&gt;Microsoft Access has these peculiar set of aggregates called &lt;b&gt;First&lt;/b&gt; and &lt;b&gt;Last&lt;/b&gt;.  We try to avoid them because while the concept is useful, we find Microsoft Access&#039;s implementation of them
a bit broken.  MS Access power users we know moving over to something like MySQL, SQL Server, and PostgreSQL often ask - &lt;em&gt;where&#039;s first and where&#039;s last?&lt;/em&gt;
First we shall go over what exactly these aggregates do in MS Access and how they are different from MIN and MAX and what they should do in an ideal world.  Then we shall create our ideal 
world in PostgreSQL.&lt;/P&gt; &lt;br /&gt;&lt;a href=&quot;http://www.postgresonline.com/journal/archives/68-More-Aggregate-Fun-Whos-on-First-and-Whos-on-Last.html#extended&quot;&gt;Continue reading &quot;More Aggregate Fun: Who&#039;s on First and Who&#039;s on Last&quot;&lt;/a&gt;
    </content:encoded>

    <pubDate>Tue, 12 Aug 2008 22:58:00 -0400</pubDate>
    <guid isPermaLink="false">http://www.postgresonline.com/journal/archives/68-guid.html</guid>
    <category>aggregates</category>
<category>msaccess</category>

</item>
<item>
    <title>Build Median Aggregate Function in SQL</title>
    <link>http://www.postgresonline.com/journal/archives/67-Build-Median-Aggregate-Function-in-SQL.html</link>
            <category>intermediate</category>
            <category>pl programming</category>
            <category>sql functions</category>
    
    <comments>http://www.postgresonline.com/journal/archives/67-Build-Median-Aggregate-Function-in-SQL.html#comments</comments>
    <wfw:comment>http://www.postgresonline.com/journal/wfwcomment.php?cid=67</wfw:comment>

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

    <author>nospam@example.com (Leo Hsu and Regina Obe)</author>
    <content:encoded>
    &lt;P&gt;One of the things we love most about PostgreSQL is the ease with which one can define new aggregate functions with even a language as 
succinct as SQL.  Normally when we have needed a median function, we&#039;ve just used the built-in median function in PL/R as we briefly demonstrated in
&lt;a href=&quot;http://www.postgresonline.com/journal/archives/6-Language-Architecture-in-PostgreSQL.html&quot; target=&quot;_blank&quot;&gt;Language Architecture in PostgreSQL&lt;/a&gt;.&lt;/P&gt;

&lt;p&gt;If all you demand is a simple median aggregate function ever then installing the whole R statistical environment so you can use PL/R is overkill and much less
portable.&lt;/P&gt;
&lt;P&gt;
In this article we will demonstrate how to create a Median function with nothing but the built-in PostgreSQL SQL language, array constructs,
and functions.
&lt;/P&gt; &lt;br /&gt;&lt;a href=&quot;http://www.postgresonline.com/journal/archives/67-Build-Median-Aggregate-Function-in-SQL.html#extended&quot;&gt;Continue reading &quot;Build Median Aggregate Function in SQL&quot;&lt;/a&gt;
    </content:encoded>

    <pubDate>Sun, 10 Aug 2008 21:10:00 -0400</pubDate>
    <guid isPermaLink="false">http://www.postgresonline.com/journal/archives/67-guid.html</guid>
    <category>aggregates</category>

</item>

</channel>
</rss>