<?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 - PLR</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>Tue, 17 Jul 2012 23:29:40 GMT</pubDate>

    <image>
        <url>http://www.postgresonline.com/journal/templates/default/img/s9y_banner_small.png</url>
        <title>RSS: Postgres OnLine Journal - PLR - 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>Building on MingW and deploying on VC compiled PostgreSQL Why and Why not</title>
    <link>http://www.postgresonline.com/journal/archives/260-Building-on-MingW-and-deploying-on-VC-compiled-PostgreSQL-Why-and-Why-not.html</link>
            <category>contrib spotlight</category>
            <category>PLR</category>
            <category>postgis</category>
    
    <comments>http://www.postgresonline.com/journal/archives/260-Building-on-MingW-and-deploying-on-VC-compiled-PostgreSQL-Why-and-Why-not.html#comments</comments>
    <wfw:comment>http://www.postgresonline.com/journal/wfwcomment.php?cid=260</wfw:comment>

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

    <author>nospam@example.com (Leo Hsu and Regina Obe)</author>
    <content:encoded>
    &lt;p&gt;We are the windows package maintainers of PostGIS.  We build these packages using MingW chain of tools. For other packages we fancy that do not come packaged with the windows VC++ builds, we also build these under mingw.   We&#039;ve described some of these already in &lt;a href=&quot;http://www.postgresonline.com/journal/archives/250-File-FDW-Family-Part-1-file_fdw.html&quot; target=&quot;_blank&quot;&gt;File FDW family&lt;/a&gt;.  For windows 32 builds we build
with the commonly known &lt;a href=&quot;http://www.mingw.org/wiki/msys/&quot;&gt;MSys/Mingw32&lt;/a&gt; chain (but an older version 1.0.11) 
because of issues we have building with the newer msys/mingw 32.  
For windows 64-bit installs, we build with the &lt;a href=&quot;http://mingw-w64.sourceforge.net/&quot; target=&quot;_blank&quot;&gt;mingw-w64&lt;/a&gt; chain and in fact 
we like the ming-w64 chain so much that we plan to migrate our Mingw32 to mingw64.  We have PostgreSQL 9.2 and PostgreSQL 9.3 successfully installing under the mingw-w64 for windows 32 just fine (older PostgreSQL we experience a winsock.h something or other error which we are working on troubleshooting.  For 64-bit we use ming-w64 for building extensions for PostgreSQL 9.0-9.2 and soon 9.3 with some minor issues. Some people have asked us, why put yourself thru this torture? Why not just build on MS VC++ for everything?  Originally we had started on mingw because PostGIS needed a Unix like environment to compile and run thru the battery of tests.  This is still the case, though PostGIS is planning a CMake move with help from &lt;a href=&quot;http://mateusz.loskot.net/&quot; target=&quot;_blank&quot;&gt;Mateusz Lostkot&lt;/a&gt; which hopefuly will provide a better cross-platform experience and allows us to integrate pgRouting (which already is on CMake). &lt;a href=&quot;http://blog.cleverelephant.ca&quot; target=&quot;_blank&quot;&gt;Paul Ramsey&lt;/a&gt; rewrote many of the regression test scripts to be completely Perl based and not require sh.  The other reality is we just prefer mingw and can&#039;t really stomach having to work with VC++. I&#039;ll describe why and why not build with mingw and deploy on VC++ compiled PostgreSQL.&lt;/p&gt;  &lt;br /&gt;&lt;a href=&quot;http://www.postgresonline.com/journal/archives/260-Building-on-MingW-and-deploying-on-VC-compiled-PostgreSQL-Why-and-Why-not.html#extended&quot;&gt;Continue reading &quot;Building on MingW and deploying on VC compiled PostgreSQL Why and Why not&quot;&lt;/a&gt;
    </content:encoded>

    <pubDate>Sun, 15 Jul 2012 23:59:00 -0400</pubDate>
    <guid isPermaLink="false">http://www.postgresonline.com/journal/archives/260-guid.html</guid>
    
</item>
<item>
    <title>PL/R Part 3: Sharing Functions across PL/R functions with plr_module</title>
    <link>http://www.postgresonline.com/journal/archives/190-PLR-Part-3-Sharing-Functions-across-PLR-functions-with-plr_module.html</link>
            <category>8.4</category>
            <category>9.0</category>
            <category>9.1</category>
            <category>intermediate</category>
            <category>pl programming</category>
            <category>PLR</category>
    
    <comments>http://www.postgresonline.com/journal/archives/190-PLR-Part-3-Sharing-Functions-across-PLR-functions-with-plr_module.html#comments</comments>
    <wfw:comment>http://www.postgresonline.com/journal/wfwcomment.php?cid=190</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://www.postgresonline.com/journal/rss.php?version=2.0&amp;type=comments&amp;cid=190</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/189-plr_part2.html&quot; target=&quot;_blank&quot;&gt;Part 2 of PL/R&lt;/a&gt; we covered how to build PL/R functions that take arrays and output textual outputs of generated R objects.  We then used this in an aggregate SQL query using array_agg. Often when you are building PL/R functions
you&#039;ll have R functions that you want to reuse many times either inside a single PL/R function or across various PL/R functions. &lt;/p&gt;

&lt;p&gt;Unfortunately, if you wanted to call a PL/R function from another PL/R function, this is not possible unless you are doing it from spi.execute call. 
There is another way to embed reusable R code in a PostgreSQL database.
In order to be able to share databases stored R code across various PL/R functions, PL/R has a feature called a plr_module.  In this tutorial
we&#039;ll learn how to create and register shareable R functions with plr_module. In the next part of this series we&#039;ll start to explore generating graphs with PL/R.&lt;/p&gt; &lt;br /&gt;&lt;a href=&quot;http://www.postgresonline.com/journal/archives/190-PLR-Part-3-Sharing-Functions-across-PLR-functions-with-plr_module.html#extended&quot;&gt;Continue reading &quot;PL/R Part 3: Sharing Functions across PL/R functions with plr_module&quot;&lt;/a&gt;
    </content:encoded>

    <pubDate>Mon, 20 Dec 2010 13:37:00 -0500</pubDate>
    <guid isPermaLink="false">http://www.postgresonline.com/journal/archives/190-guid.html</guid>
    <category>plr</category>
<category>postgis</category>
<category>r</category>

</item>
<item>
    <title>PL/R Part 2: Functions that take arguments and the power of aggregation</title>
    <link>http://www.postgresonline.com/journal/archives/189-PLR-Part-2-Functions-that-take-arguments-and-the-power-of-aggregation.html</link>
            <category>8.4</category>
            <category>9.0</category>
            <category>9.1</category>
            <category>intermediate</category>
            <category>pl programming</category>
            <category>PLR</category>
    
    <comments>http://www.postgresonline.com/journal/archives/189-PLR-Part-2-Functions-that-take-arguments-and-the-power-of-aggregation.html#comments</comments>
    <wfw:comment>http://www.postgresonline.com/journal/wfwcomment.php?cid=189</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://www.postgresonline.com/journal/rss.php?version=2.0&amp;type=comments&amp;cid=189</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/188-plr_part1.html&quot; target=&quot;_blank&quot;&gt;Intro to PL/R and R&lt;/a&gt;, we covered how to enable PL/R language in the database and wrote some PL/R functions
that rendered plain text reports using the R environment.  What makes combining R and PostgreSQL in
PL/R most powerful is when you can start writing SQL summary queries that use R functions like any other SQL function. &lt;/p&gt;

&lt;p&gt;In this next example, we&#039;ll be using PostGIS test runs from tests we autogenerated from the &lt;a href=&quot;http://www.postgis.org/documentation/manual-svn/&quot; target=&quot;_blank&quot;&gt;Official PostGIS documentation&lt;/a&gt; (Documentation Driven Testing (DDT))
as described in the  &lt;a href=&quot;http://trac.osgeo.org/postgis/wiki/DevWikiGardenTest&quot; target=&quot;_blank&quot;&gt;Garden Test&lt;/a&gt; section of the PostGIS Developer wiki.  
We&#039;ve also updated some of our logging generator and test patterns so future results may not represent what we demonstrated in the last article. &lt;/p&gt;
&lt;p&gt;On a side note: Among the changes in the tests was to introduce more variants of the &lt;a href=&quot;http://www.postgis.org/pipermail/postgis-devel/2010-December/010776.html&quot; target=&quot;_balnk&quot;&gt;Empty Geometry now supported by PostGIS 2.0&lt;/a&gt;.  
Our beloved PostGIS 2.0 trunk is at the moment somewhat unstable when working with these new forms of emptiness and stuffing geometries in inappropriate places. At the moment it doesn&#039;t survive through  the mindless machine gun battery of tests we have mercilessly inflicted.
It&#039;s been great fun trying to build a better dummy while watching &lt;a href=&quot;http://blog.cleverelephant.ca/&quot; target=&quot;_blank&quot;&gt;Paul&lt;/a&gt; run around patching holes to make the software more dummy proof as the dummy stumbles across questionable but amusing PostGIS use cases not gracefully handled by his new serialization and empty logic. &lt;/p&gt;

&lt;p&gt;On yet another side note, it&#039;s nice to 
see that others are doing similar wonderful things with documentation.  Check out &lt;a href=&quot;http://eulerto.blogspot.com/2010/11/comment-on-catalog-tables.html&quot; target=&quot;_blank&quot;&gt;Euler&#039;s comment on catalog tables&lt;/a&gt;
where he uses the PostgreSQL SGML documentation to autogenerate PostgreSQL catalog table comments using &lt;a href=&quot;http://openjade.sourceforge.net/doc/sx.htm&quot; target-&quot;_blank&quot;&gt;OpenJade&#039;s OSX to convert the SGML to XML&lt;/a&gt; and then XSL similar to what we did with PostGIS documentation to autogenerate PostGIS function/type comments and as a platform
for our test generator.  &lt;/p&gt;

&lt;p&gt;For our next exercises we&#039;ll be using the power of aggregation to push data into R instead of &lt;b&gt;pg.spi.execute&lt;/b&gt;. This will make our functions far more reusable and versatile.&lt;/p&gt; &lt;br /&gt;&lt;a href=&quot;http://www.postgresonline.com/journal/archives/189-PLR-Part-2-Functions-that-take-arguments-and-the-power-of-aggregation.html#extended&quot;&gt;Continue reading &quot;PL/R Part 2: Functions that take arguments and the power of aggregation&quot;&lt;/a&gt;
    </content:encoded>

    <pubDate>Fri, 10 Dec 2010 01:38:00 -0500</pubDate>
    <guid isPermaLink="false">http://www.postgresonline.com/journal/archives/189-guid.html</guid>
    <category>plr</category>
<category>postgis</category>
<category>r</category>

</item>
<item>
    <title>Quick Intro to R and PL/R - Part 1</title>
    <link>http://www.postgresonline.com/journal/archives/188-Quick-Intro-to-R-and-PLR-Part-1.html</link>
            <category>9.0</category>
            <category>gis</category>
            <category>intermediate</category>
            <category>pl programming</category>
            <category>PLR</category>
    
    <comments>http://www.postgresonline.com/journal/archives/188-Quick-Intro-to-R-and-PLR-Part-1.html#comments</comments>
    <wfw:comment>http://www.postgresonline.com/journal/wfwcomment.php?cid=188</wfw:comment>

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

    <author>nospam@example.com (Leo Hsu and Regina Obe)</author>
    <content:encoded>
    &lt;p&gt;In this article we&#039;ll provide a summary of what PL/R is and how to get running with it.  Since we don&#039;t like repeating ourselves,
we&#039;ll refer you to an article we wrote a while ago which is still fairly relevant today called &lt;a href=&quot;http://www.bostongis.com/PrinterFriendly.aspx?content_name=postgresql_plr_tut01&quot; target=&quot;_blank&quot;&gt;Up and Running with PL/R (PLR) in PostgreSQL: An almost Idiot&#039;s Guide&lt;/a&gt;
and just fill in the parts that have changed.  We should note that particular series was more geared toward the spatial database programmer (PostGIS in particular).  There is a lot of overlap between the PL/R, R, and PostGIS user-base which is comprised
of many environmental scientists and researchers in need of powerful charting and stats tools to analyse their data who are high on the smart but low on the money human spectrum. &lt;/p&gt;
&lt;p&gt;This series will be more of a general PL/R user perspective.  We&#039;ll follow more of the same style we did with &lt;a href=&quot;http://www.postgresonline.com/journal/archives/99-Quick-Intro-to-PLPython.html&quot; target=&quot;_blank&quot;&gt;Quick Intro to PL/Python&lt;/a&gt;. We&#039;ll end our series with a PL/R cheatsheet similar to what we had for PL/Python.&lt;/p&gt;
&lt;p&gt;As stated in our &lt;a href=&quot;http://www.postgresonline.com/journal/archives/187-postgis20_state_plr.html&quot; target=&quot;_blank&quot;&gt;State of PostGIS&lt;/a&gt; article, we&#039;ll be using log files we generated from our PostGIS stress tests.  These stress tests were auto-generated from the PostGIS official documentation.  
The raster tests are comprised of 2,095 query executions exercising all the pixel types supported.  The geometry/geograpy tests are comprised of 65,892 spatial SQL queries exercising every PostGIS geometry/geography supported in PostGIS 2.0 -- yes this includes TINS, Triangles,Polyhedral Surfaces, Curved geometries and all dimensions of them.
Most queries are unique. If you are curious to see what these log tables look like or want to follow along with these exercises, you can download the tables from &lt;a href=&quot;/demos/plr/postgis20gardentests.zip&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;h4&gt;What is R and PL/R and why should you care?&lt;/h4&gt;
&lt;p&gt;R is both a language and an environment for doing statistics and generating graphs and plots.  It is GNU-licensed and a common favorite of Universities and Research institutions. PL/R is a procedural language for PostgreSQL that allows you to write database stored functions
in R.  R is a set-based and domain specific language similar to SQL except unlike the way relational databases treat data, it thinks of data as matrices, lists and vectors.  I tend to think of it as a cross between LISP and SQL though more experienced Lisp and R users will probably disagree with me on that.  This makes it easier in many cases to tabulate data both across columns as well as across rows.
The examples we will show in these exercises, could be done in SQL, but they are much more succinct to write in R.  In addition to the language itself, there are a whole wealth of statistical and graphing functions available in R that you will not 
find in any relational database.  These functions are growing as more people contribute packages.  Its packaging system called Comprehensive R Archive (CRAN) is similar in concept to Perl&#039;s CPAN and the in the works &lt;a href=&quot;http://blog.pgxn.org/&quot; target=&quot;_blank&quot;&gt;PGXN for PostgreSQL&lt;/a&gt;.&lt;/p&gt; &lt;br /&gt;&lt;a href=&quot;http://www.postgresonline.com/journal/archives/188-Quick-Intro-to-R-and-PLR-Part-1.html#extended&quot;&gt;Continue reading &quot;Quick Intro to R and PL/R - Part 1&quot;&lt;/a&gt;
    </content:encoded>

    <pubDate>Sun, 28 Nov 2010 14:19:00 -0500</pubDate>
    <guid isPermaLink="false">http://www.postgresonline.com/journal/archives/188-guid.html</guid>
    <category>plr</category>
<category>postgis</category>
<category>r</category>

</item>
<item>
    <title>The State of PostGIS, Joys of Testing, and PLR the Prequel</title>
    <link>http://www.postgresonline.com/journal/archives/187-The-State-of-PostGIS,-Joys-of-Testing,-and-PLR-the-Prequel.html</link>
            <category>9.0</category>
            <category>editor note</category>
            <category>gis</category>
            <category>PLR</category>
            <category>postgis</category>
    
    <comments>http://www.postgresonline.com/journal/archives/187-The-State-of-PostGIS,-Joys-of-Testing,-and-PLR-the-Prequel.html#comments</comments>
    <wfw:comment>http://www.postgresonline.com/journal/wfwcomment.php?cid=187</wfw:comment>

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

    <author>nospam@example.com (Leo Hsu and Regina Obe)</author>
    <content:encoded>
    &lt;p&gt;I&#039;ve always enjoyed dismantling things.  Deconstruction was a good way of analyzing how things were built by cataloging all the ways
I could dismantle or destroy them.  I experimented with mechanical systems, electrical circuitry, chemicals and biological systems sometimes coming close to bodily harm. In later years I decided to play it safe and just stick with programming and computer simulation 
as a convenient channel to enjoy my destructive pursuits.
 Now getting to the point of this article.&lt;/p&gt;
&lt;p&gt;In later articles, I&#039;ll start to demonstrate the use of &lt;a href=&quot;http://www.joeconway.com/plr/&quot; target=&quot;_blank&quot;&gt;PL/R&lt;/a&gt;, the procedural language for PostgreSQL that allows you to program functions in the statistical language and Environment R.  To 
make these examples more useful, I&#039;ll be analyzing data generated from PostGIS tests I&#039;ve been working on for stress testing the upcoming PostGIS 2.0. PostGIS 2.0 is a major
and probably the most exciting release for us.  &lt;a href=&quot;http://blog.cleverelephant.ca&quot; target=&quot;_blank&quot;&gt;Paul Ramsey&lt;/a&gt; did a summary talk recently of Past, Present, Future of PostGIS at &lt;a href=&quot;http://www.ustream.tv/recorded/10667125&quot; target=&quot;_blank&quot;&gt;State of PostGIS FOSS4G Japan http://www.ustream.tv/recorded/10667125&lt;/a&gt;
which provides a brief glimpse of what&#039;s in store in 2.0.&lt;/p&gt; &lt;br /&gt;&lt;a href=&quot;http://www.postgresonline.com/journal/archives/187-The-State-of-PostGIS,-Joys-of-Testing,-and-PLR-the-Prequel.html#extended&quot;&gt;Continue reading &quot;The State of PostGIS, Joys of Testing, and PLR the Prequel&quot;&lt;/a&gt;
    </content:encoded>

    <pubDate>Tue, 23 Nov 2010 18:22:00 -0500</pubDate>
    <guid isPermaLink="false">http://www.postgresonline.com/journal/archives/187-guid.html</guid>
    <category>plr</category>
<category>postgis</category>

</item>
<item>
    <title>PostGIS 1.5.0 out and PLR working on Windows 8.3-8.4 installs</title>
    <link>http://www.postgresonline.com/journal/archives/151-PostGIS-1.5.0-out-and-PLR-working-on-Windows-8.3-8.4-installs.html</link>
            <category>8.3</category>
            <category>8.4</category>
            <category>pl programming</category>
            <category>PLR</category>
            <category>postgis</category>
    
    <comments>http://www.postgresonline.com/journal/archives/151-PostGIS-1.5.0-out-and-PLR-working-on-Windows-8.3-8.4-installs.html#comments</comments>
    <wfw:comment>http://www.postgresonline.com/journal/wfwcomment.php?cid=151</wfw:comment>

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

    <author>nospam@example.com (Leo Hsu and Regina Obe)</author>
    <content:encoded>
    &lt;h4&gt;PostGIS 1.5.0 is finally out&lt;/h4&gt;
&lt;p&gt;I&#039;m happy to report that after a long haul, we have finally released PostGIS 1.5.0. 
Two months late, but there it is, and its a really great release I think;  Perhaps the best release ever.
&lt;/p&gt;
&lt;p&gt;Details on what makes this release so special.  &lt;a href=&quot;http://blog.opengeo.org/2010/02/05/postgis-1-5/&quot; target=&quot;_blank&quot;&gt;The geodetic support&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Summary excerpted from &lt;a href=&quot;http://www.postgis.org/pipermail/postgis-devel/2010-February/008611.html&quot; target=&quot;_blank&quot;&gt;Paul&#039;s slightly premature announcement&lt;/a&gt;
&lt;pre style=&quot;font-size:small&quot;&gt;
February 4, 2010

The PostGIS development team has, after a long course of reflection
and a detailed self-examination of our various personal failings,
decided to release PostGIS 1.5.0 to the public.

  &lt;a href=&quot;http://postgis.org/download/postgis-1.5.0.tar.gz&quot;&gt;http://postgis.org/download/postgis-1.5.0.tar.gz&lt;/a&gt;

This new version of PostGIS includes a new &quot;geography&quot; type for
managing geodetic (lat/lon) data, performance-enhanced distance
calculations, GML and KML format readers, an improved shape loading
GUI, and other new features as well.

Especial thanks to:

* Dave Skea for algorithms and mathematics necessary to support
spherical geometry
* Nicklas Avén for the new performance enhanced distance calculations
and other distance-related functions
* Sandro Santilli for new buffering features (end caps and style options)
* Olivier Courtin for GML/KML input functions
* Guillaume Lelarge for support for the upcoming PgSQL 9.0
* George Silva for an example implementation of history tables
* Vincent Picavet for Hausdorff distance calculations
* The maintainers of GEOS, Proj4, and LibXML, without whom we would
have less of a spatial database

Love, the PostGIS project steering committee,

Mark Cave-Ayland
Kevin Neufeld
Regina Obe
Paul Ramsey
&lt;/pre&gt;
&lt;/p&gt;
 &lt;br /&gt;&lt;a href=&quot;http://www.postgresonline.com/journal/archives/151-PostGIS-1.5.0-out-and-PLR-working-on-Windows-8.3-8.4-installs.html#extended&quot;&gt;Continue reading &quot;PostGIS 1.5.0 out and PLR working on Windows 8.3-8.4 installs&quot;&lt;/a&gt;
    </content:encoded>

    <pubDate>Sun, 07 Feb 2010 00:58:00 -0500</pubDate>
    <guid isPermaLink="false">http://www.postgresonline.com/journal/archives/151-guid.html</guid>
    
</item>
<item>
    <title>Choosing the right Database Procedural Language PL</title>
    <link>http://www.postgresonline.com/journal/archives/50-Choosing-the-right-Database-Procedural-Language-PL.html</link>
            <category>beginner</category>
            <category>mysql</category>
            <category>pl programming</category>
            <category>plperl</category>
            <category>plpgsql</category>
            <category>PLR</category>
            <category>sql functions</category>
            <category>sql server</category>
    
    <comments>http://www.postgresonline.com/journal/archives/50-Choosing-the-right-Database-Procedural-Language-PL.html#comments</comments>
    <wfw:comment>http://www.postgresonline.com/journal/wfwcomment.php?cid=50</wfw:comment>

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

    <author>nospam@example.com (Leo Hsu and Regina Obe)</author>
    <content:encoded>
    &lt;P&gt;One of the great selling points of PostgreSQL is its pluggable PL language architecture.  MySQL is known for its pluggable storage and 
PostgreSQL is known for its pluggable PL language architecture.  From &lt;a href=&quot;http://www.scribd.com/doc/2575733/The-future-of-MySQL-The-Project&quot; target=_blank&gt;Monty&#039;s notes on slide 12&lt;/a&gt; looks like MySQL 
may be working on a pluggable PL language architecture of their own.
The most common of these languages are the all-purpose languages SQL and C (these are built-in and not really PLs like the others, but we&#039;ll throw them in there),
&lt;a href=&quot;http://www.postgresql.com.cn/docs/8.3/static/plpgsql.html&quot; target=_blank&gt;PLPgSQL&lt;/a&gt; which is also built-in but not always enabled, &lt;a href=&quot;http://www.postgresql.org/docs/8.3/static/plperl.html&quot; target=_blank&gt;PL/Perl&lt;/a&gt;, &lt;a href=&quot;http://www.postgresql.org/docs/8.3/interactive/plpython.html&quot; target=_blank&gt;PL/Python&lt;/a&gt;, and the domain specific languages &lt;a href=&quot;http://joeconway.com/plr/doc/index.html&quot; target=_blank&gt;PL/R&lt;/a&gt;, &lt;A href=&quot;http://plsh.projects.postgresql.org/&quot; target=_blank&gt;PL/SH&lt;/A&gt; and gaining popularity Skype released &lt;a href=&quot;https://developer.skype.com/SkypeGarage/DbProjects/PlProxy&quot; target=_blank&gt;PL/Proxy&lt;/a&gt;.  
There are others in the family such as &lt;a href=&quot;http://www.postgresql.org/docs/8.3/interactive/pltcl.html&quot; target=_blank&gt;PL/Tcl&lt;/a&gt;, &lt;a href=&quot;https://projects.commandprompt.com/public/plphp&quot; target=_blank&gt;PL/PHP&lt;/a&gt;, &lt;a href=&quot;http://raa.ruby-lang.org/project/pl-ruby/&quot; target=_blank&gt;PL/Ruby&lt;/a&gt;, &lt;a href=&quot;http://plscheme.projects.postgresql.org/&quot; target=_blank&gt;PL/Scheme (a dialect of Lisp)&lt;/a&gt;, &lt;a href=&quot;http://wiki.tada.se/display/pljava/Home&quot; target=_blank&gt;PL/Java&lt;/a&gt;, &lt;a href=&quot;http://pllua.projects.postgresql.org/&quot; target=_blank&gt;PL/Lua&lt;/a&gt; and &lt;a href=&quot;http://pgfoundry.org/projects/pllolcode&quot; target=_blank&gt;PL/LOLCode (for kicks and as a reference implementation.  Think of LOLCode as PostgreSQL Pluggable PL equivalent of MySQL&#039;s BLACK HOLE storage engine.)&lt;/a&gt; .
&lt;/P&gt;

&lt;P&gt;The other interesting thing about the PostgreSQL PL language architecture is that it is a fairly thin wrapper around these languages.
This means the kind of code you write in those languages is pretty much what you would write if you were doing general programming
in those languages minus some spi calls. Since the handler is a just a thin wrapper around the environment, the language environment must be installed on the database server before you can use the PL language handler.  This means you can have these functions utilized in your SQL statements and you can write
in a language you feel comfortable with if you can get the darn PL compiled for your environment or someone has already kindly compiled it for your environment or that it is even compilable for your environment.  The pluggable PL architecture means you can 
write a PL Handler for your favorite language or invent your own language that you can run in the database.   In the end 
the barrier between code,data, and semantic constructs is more of a constraint imposed by compilers.  If you have any doubts about the above statement, you need only look at some javascript injection attacks
to bring the statement home. One of my fantasies is 
developing a language that morphs itself, that utilizes the database as its morphing engine and its OS and that breaks the illusion of data being data, code being code, and lacks rigid semantics.  
Of the languages we have worked with, &lt;a href=&quot;http://en.wikipedia.org/wiki/Smalltalk&quot; target=_blank&gt;SmallTalk&lt;/a&gt; comes closest to a language that satisfies these ideals and Lisp to a much lesser extent.  Lisp lacked the semantic elegance of SmallTalk among other things.
&lt;/P&gt;

&lt;P&gt;Most people are used to having their procedural language push their data around.  PL code living in PostgreSQL allows your data to push your procedural code around in a set-based way.  This is a simple but pretty powerful feature since data is in general more fluid than code. For interpretated/just-in time compiled languages it can live in the database, for compiled it has to call compiled functions. &lt;/P&gt; &lt;br /&gt;&lt;a href=&quot;http://www.postgresonline.com/journal/archives/50-Choosing-the-right-Database-Procedural-Language-PL.html#extended&quot;&gt;Continue reading &quot;Choosing the right Database Procedural Language PL&quot;&lt;/a&gt;
    </content:encoded>

    <pubDate>Sat, 10 May 2008 06:58:00 -0400</pubDate>
    <guid isPermaLink="false">http://www.postgresonline.com/journal/archives/50-guid.html</guid>
    
</item>
<item>
    <title>Language Architecture in PostgreSQL</title>
    <link>http://www.postgresonline.com/journal/archives/6-Language-Architecture-in-PostgreSQL.html</link>
            <category>intermediate</category>
            <category>pl programming</category>
            <category>plpgsql</category>
            <category>PLR</category>
            <category>sql functions</category>
    
    <comments>http://www.postgresonline.com/journal/archives/6-Language-Architecture-in-PostgreSQL.html#comments</comments>
    <wfw:comment>http://www.postgresonline.com/journal/wfwcomment.php?cid=6</wfw:comment>

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

    <author>nospam@example.com (Leo Hsu and Regina Obe)</author>
    <content:encoded>
    &lt;p&gt;Perhaps one of the most unique and exciting things that makes PostgreSQL stand out from other database systems, are the numerous choices of languages one can use to create database functions, triggers and define new aggregate functions with.  Not only can you use various languages to write your database stored functions with, but often times the code you write lives right in the database.  You have no idea how cool this is until you see it in action.&lt;/p&gt;

&lt;p&gt;The other interesting thing about the PostgreSQL language architecture is the relative ease with which new languages can be incorporated in the system.&lt;/p&gt;

&lt;h4&gt;Native Languages of PostgreSQL&lt;/h4&gt;
&lt;p&gt;There are 3 languages that come packaged with PostgreSQL (2 non-PL ones are installed automatically and not even listed as languages (C and SQL) in the languages section of a db).  The defacto PL/PgSQL procedural language is available for install in all PostgreSQL distributions, but need not be installed in a db by default .  
&lt;/p&gt;&lt;ol&gt;
&lt;li&gt;&lt;i&gt;C Extern&lt;/i&gt; which allows for binding C libraries as functions.  C Extern is similar to the way languages like MySQL bind C libraries for use in DB or the way SQL Server 2005+ binds .NET assemblies as functions in SQL Server.&lt;/li&gt;
&lt;li&gt;&lt;i&gt;SQL&lt;/i&gt; - this is a non-procedural language.  It allows one to write parameterized db stored functions with plain SQL, but lacks procedural logic constructs such as IF, FOR, WHILE and so forth.  It is basically a macro substitution language.  Functions written in this way are basically in-lined in with the queries they are used (except in case of STABLE, IMMUTABLE defined in which case cached results are often used) in so they are more easily optimizable than functions written in other languages.  NOTE: that MySQL 5+ also has a Procedural language called SQL, but the MySQL SQL language is a procedural language more in line with PostgreSQL &lt;i&gt;pl/pgsql&lt;/i&gt; and closer in syntax to DB2&#039;s SQL PL.  I&#039;ll also note that DB2 has a concept of INLINE SQL PL which is kind of like PostgreSQL sql language, although a bit more powerful.&lt;/li&gt;
&lt;li&gt;&lt;i&gt;PL/PgSQL&lt;/i&gt; - this is PostgreSQL defacto Procedural Language.  It is not always installed by default in a database but the language handler is always available for installation.  The equivalent but slightly different in syntax in other systems would be Transact SQL in SQL Server/Sybase, PL/SQL in Oracle, SQL in MySQL5+, and SQL PL in DB2.&lt;/li&gt; 
&lt;/ol&gt;

&lt;h4&gt;The PL languages&lt;/h4&gt;
&lt;p&gt;Aside from PL/pgSQL there are numerous other procedural languages that one can use to create database stored functions and triggers.  Some of these languages are fairly stable and even more are experimental.  Some are only supported on Unix/Linux, but many are supported on Unix/Linux/MacOS/windows.  In any case there are 3 key components needed before you can start using a new language: 

&lt;/p&gt;&lt;ol&gt;
    &lt;li&gt;The environment for the language - e.g. PHP, Perl, Python, Ruby, Java, R etc. interpreter and libraries installed on the PostgreSQL server box&lt;/li&gt;
    &lt;li&gt;The compiled call handler function - this is a C-compiled function that does the transfer between the PostgreSQL environment and the language environment.&lt;/li&gt;&lt;li&gt;The language registered in the database you wish to use it in.&lt;/li&gt;&lt;/ol&gt;&lt;p&gt; &lt;/p&gt;

&lt;h3&gt;Registering a language in a Database&lt;/h3&gt;
&lt;p&gt;For &lt;i&gt;pl/pgsql&lt;/i&gt; items 1 and 2 are already done if you have a working PostgreSQL install.  In order to accomplish item 3, you may need to do the following from psql or PgAdmin III query window.

&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
 CREATE TRUSTED PROCEDURAL LANGUAGE &#039;plpgsql&#039;
  HANDLER plpgsql_call_handler
  VALIDATOR plpgsql_validator;
&lt;/code&gt;
&lt;/pre&gt;

&lt;p&gt;Alternatively you can run &lt;em&gt;createlang plpgsql somedb&lt;/em&gt; from commandline.   Note createlang is a command line program that is located in the &lt;b&gt;bin&lt;/b&gt; folder of your PostgreSQL install.&lt;/p&gt;

&lt;p&gt;To see a list of procedural languages that you already have call handlers registered for in PostgreSQL.  These are the languages you can register in your specific database - do a 
&lt;/p&gt;
&lt;code&gt;SELECT * FROM pg_catalog.pg_pltemplate&lt;/code&gt;

&lt;h4&gt;A Flavor of the Procedural Languages (PLs)&lt;/h4&gt;
&lt;p&gt;In this section, we&#039;ll show a brief sampling of what functions look like written in various PLs.  These are not to suggest they are the only ones that exist.  For these examples, I&#039;m going to use the $ quoting syntax introduced in PostgreSQL 8.0 which allows for not having to escape out single quotes.&lt;/p&gt;

&lt;h5&gt;SQL - the not PL language&lt;/h5&gt;
&lt;p&gt;For basic CRUD stuff,selects and simple functions, nothing hits the spot like just plain old SQL.  Since this is such a common choice and often the best choice - here are 3 examples.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;CREATE OR REPLACE FUNCTION cp_simpleupdate(thekey integer, thevalue varchar(50))
  RETURNS void AS
	$BODY$
		UPDATE testtable SET test_stuff = $2 WHERE test_id = $1
	$BODY$
  LANGUAGE &#039;sql&#039; VOLATILE;
&lt;/code&gt;

--Example use
SELECT cp_simpleupdate(1, &#039;set to this&#039;); 
&lt;/pre&gt;

&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;
--Here is a simple example to simulate the MySQL 5.0 function
CREATE OR REPLACE FUNCTION from_unixtime(unixts integer)
  RETURNS timestamp without time zone AS
$BODY$SELECT CAST(&#039;epoch&#039; As timestamp) + ($1 * INTERVAL &#039;1 second&#039;) $BODY$
  LANGUAGE &#039;sql&#039; IMMUTABLE;
  
  --Example use
  SELECT from_unixtime(1134657687); 
  SELECT from_unixtime(tbl.fromsomefield) FROM tbl;
&lt;/code&gt;
&lt;/pre&gt;
&lt;br /&gt;
&lt;pre&gt;
&lt;code&gt;
CREATE OR REPLACE FUNCTION cp_test(subject varchar)
  RETURNS SETOF testtable AS
  $BODY$
	SELECT * FROM testtable where test_stuff LIKE $1;
	$BODY$
  LANGUAGE &#039;sql&#039; VOLATILE;
  --Example use
  SELECT * FROM cp_test(&#039;%stuff%&#039;);
&lt;/code&gt;
&lt;/pre&gt;

&lt;pre&gt;
&lt;code&gt;
  CREATE OR REPLACE FUNCTION cp_testusingoutparams(subject varchar, out test_id int, out test_stuff varchar)
  RETURNS SETOF record AS
$BODY$
	SELECT test_id, test_stuff FROM testtable where test_stuff LIKE $1;
$BODY$
  LANGUAGE &#039;sql&#039; VOLATILE;

--Example use - Note the subtle difference - the second syntax with out parameters is newer
-- It allows you to get around the messy issue of when you are returning a record type
--That a record type has no specific type.
SELECT * FROM cp_usingoutparams(&#039;%stuff%&#039;);
&lt;/code&gt;
&lt;/pre&gt;

&lt;p&gt;For details on using out parameters, check out Robert Treat&#039;s &lt;a href=&quot;http://people.planetpostgresql.org/xzilla/index.php?/archives/149-guid.html&quot; target=_blank&gt;out parameter sql &amp;amp; plpgsql examples&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;PLPGSQL - a real PL Language&lt;/h4&gt;
&lt;p&gt;For more complex logic and massaging of results before sending back.  You need something more powerful than standard SQL. 
Below are some examples using PLPGSQL.
&lt;/p&gt;


&lt;pre&gt;
&lt;code&gt;
CREATE OR REPLACE FUNCTION cp_harderupdate(thekey integer, thevalue varchar)
RETURNS void AS
$BODY$
BEGIN
	IF EXISTS(SELECT test_id FROM testtable WHERE test_id = thekey) THEN 
		UPDATE testtable SET test_stuff = thevalue WHERE test_id = thekey;
	ELSE
		INSERT INTO testtable(test_id, test_stuff) VALUES(thekey, thevalue);
	END IF;
     RETURN;
END;
$BODY$
LANGUAGE &#039;plpgsql&#039; VOLATILE;

--Example use
SELECT cp_harderupdate(1, &#039;this is more stuff&#039;);

&lt;/code&gt;
&lt;/pre&gt;

&lt;h4&gt;Using PL/Perl&lt;/h4&gt;
&lt;CODE&gt;
&lt;PRE&gt;
CREATE OR REPLACE FUNCTION get_neworders() RETURNS SETOF orders AS $$
    my $rv = spi_exec_query(&#039;select * from orders where processed IS NULL;&#039;);
    my $status = $rv-&gt;{status};
    my $nrows = $rv-&gt;{processed};
    foreach my $rn (0 .. $nrows - 1) {
        my $row = $rv-&gt;{rows}[$rn];
        return_next($row);
    }
    return undef;
$$ LANGUAGE plperl;
&lt;/PRE&gt;
&lt;/CODE&gt;

&lt;h4&gt;Using PL/R a language and environment for statistics&lt;/h4&gt;
&lt;P&gt;One of my favorite PL languages to program is PL/R.  The reason for this is that the R statistical environment is such a rich environment for doing statistical processing.  It now is also supported on windows as well as Mac and Linux.&lt;/p&gt;

&lt;P&gt;To learn more about R and installing PL/R.  Check out our Boston GIS article &lt;i&gt;&lt;a href=&quot;http://www.bostongis.com/PrinterFriendly.aspx?content_name=postgresql_plr_tut01&quot; target=_blank&gt;PLR Part 1: Up and Running with PL/R (PLR) in PostgreSQL: An almost Idiot&#039;s Guide&lt;/a&gt;&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;Below is the classic median aggregate function in R.  It uses the native median function in the R environment to create a PostgreSQL aggregate median function&lt;/p&gt;
&lt;PRE&gt;
&lt;CODE&gt;
CREATE or REPLACE FUNCTION r_median(_float8) 
	returns float as $BODY$ median(arg1) $BODY$ language &#039;plr&#039;;

CREATE AGGREGATE median (
  sfunc = plr_array_accum,
  basetype = float8,
  stype = _float8,
  finalfunc = r_median
);

--Example use
SELECT median(age) As themedian_age, period_year 
        FROM crimestats GROUP BY period_year ORDER BY period_year;
&lt;/CODE&gt;
&lt;/PRE&gt;

&lt;P&gt;We will be covering PLR in greater detail in another article.&lt;/P&gt; 
    </content:encoded>

    <pubDate>Fri, 30 Nov 2007 00:00:00 -0500</pubDate>
    <guid isPermaLink="false">http://www.postgresonline.com/journal/archives/6-guid.html</guid>
    
</item>

</channel>
</rss>