How about the CASE statement to throw specific years into specific columns? Works if years/scenarios are limited/known. <br><br><a href="http://www.postgresql.org/docs/8.4/static/functions-conditional.html">http://www.postgresql.org/docs/8.4/static/functions-conditional.html</a><br>

<br>Does this help?<br>Mark<br><br><br><div class="gmail_quote">On Mon, Apr 19, 2010 at 1:24 PM, John Abraham <span dir="ltr"><<a href="mailto:jabraham@ucalgary.ca">jabraham@ucalgary.ca</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

We have a bunch of tables with columns like this:<br>
<br>
*GeometryUniqueID<br>
*Year<br>
*Scenario<br>
Value<br>
<br>
where * indicates the primary key<br>
<br>
(And, of course, a separate table for the Geometry<br>
<br>
*GeometryUniqueID<br>
TheGeometry)<br>
<br>
To compare values across scenarios with MapServer, QGIS, ArcGIS etc. we need it like this<br>
<br>
*GeometryUniqueID<br>
TheGeometry<br>
Year1Scenario1Value<br>
Year1Scenario2Value<br>
Year1Scenario3Value<br>
<br>
and to compare values across years we need it like this<br>
<br>
*GeometryUniqueID<br>
TheGeometry<br>
Year1Scenario1Value<br>
Year2Scenario1Value<br>
Year3Scenario1Value<br>
<br>
That is, we want to compare values across scenarios and across years for the same geometry.  But we've normalized all our tables so that there is a row for each unique combination of scenario and year.  And, unfortunately, all of the GIS tools that will plot our data seem to expect the data to be in different columns in the same row (i.e., not normalized, at least not to my mind).<br>


<br>
Is there a standard approach to appending each column to a view so that the PostGIS layer contains comparable values in different columns?<br>
<br>
Right now we're thinking of a fairly complex select that joins the table to itself once for each year (or each scenario) but that doesn't feel right for many reasons, not the least of which we need to know the number of years (or scenarios) before we can write the view.<br>


<br>
Thanks in advance.  I don't want to reinvent the wheel here.  Crosstabbing in SQL is always hard but I bet someone on this list has solved this before.<br>
<font color="#888888">--<br>
John Abraham<br>
<a href="mailto:jabraham@ucalgary.ca">jabraham@ucalgary.ca</a><br>
_______________________________________________<br>
postgis-users mailing list<br>
<a href="mailto:postgis-users@postgis.refractions.net">postgis-users@postgis.refractions.net</a><br>
<a href="http://postgis.refractions.net/mailman/listinfo/postgis-users" target="_blank">http://postgis.refractions.net/mailman/listinfo/postgis-users</a><br>
</font></blockquote></div><br>