Re: pivot-like transformation

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

Joe Conway schrieb:

> 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 don't like the idea to have a table in another schema in order to
create a pivot-like arrangement. Anyway, this wasn't really my need. I
got stuck at the very basics (sorry for that) - reading data from a
table, doing something with them, like printing to the screen. I tried
the example at
http://www.postgresql.org/docs/7.4/static/plpgsql-declarations.html#PLPGSQL-DECLARATION-ROWTYPES
and got the error message something like "table_name returns more then
one row...". I cannot recall it accurately since I did it at home and
now I'm at work.

>> 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

...at first

Best regards, Torsten

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message sad 2004-06-21 08:48:51 feature request
Previous Message Luis Neves 2004-06-21 06:29:06 Strange behaviour updating primary key column.