Re: pivot-like transformation

From: Joe Conway <mail(at)joeconway(dot)com>
To: Torsten Lange <t(dot)lange(at)ufz(dot)de>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: pivot-like transformation
Date: 2004-06-20 22:15:39
Message-ID: 40D60C8B.3060609@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Torsten Lange wrote:
> Hello,
> I have a table with measurement values and columns like this:
> analyses(id, sample_id, parameter[temperatur...], value, unit[?C...], error)
>
> With PL/PgSQL at the end I want try to perform a pivot-like arrangement of
> these data:
> sample_id|Temperature [?C]|parameter2 [mg/L]|...|parameterN [L/year]
> ---------+----------------+-----------------+---+-------------------
> 5 | 23.00| 0.036|...| 35.1

Not a direct answer with respect to plpgsql, but for pivot table
functionality see the contrib/tablefunc function crosstab().

> I also found very few sources about handling of arrays and how to fill them up
> with query results... things like this. Does anyone know a more comprehensive
> source?

Have you looked at the online docs?
http://www.postgresql.org/docs/7.4/static/arrays.html
http://www.postgresql.org/docs/7.4/static/functions-array.html
http://www.postgresql.org/docs/7.4/static/functions-comparisons.html
http://www.postgresql.org/docs/7.4/static/sql-expressions.html#SQL-SYNTAX-ARRAY-CONSTRUCTORS

HTH,

Joe

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Josh Berkus 2004-06-21 04:48:00 Re: use of a composite type in CREATE TABLE?
Previous Message Markus Bertheau 2004-06-20 21:22:13 question about which column(s) are the right foreign key