X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 82602D1B19C for ; Mon, 21 Jun 2004 05:09:01 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 73626-02 for ; Mon, 21 Jun 2004 08:09:02 +0000 (GMT) Received: from mr1.ufz.de (mr1.ufz.de [141.65.7.22]) by svr1.postgresql.org (Postfix) with ESMTP id E8B24D1B220 for ; Mon, 21 Jun 2004 05:08:58 -0300 (ADT) Received: from localhost (localhost.localdomain [127.0.0.1]) by localhost (Postfix) with ESMTP id CDB423180D5 for ; Mon, 21 Jun 2004 10:08:58 +0200 (CEST) Received: from mr1.ufz.de ([141.65.7.22]) by localhost (mr1 [141.65.7.22]) (amavisd-new, port 10024) with ESMTP id 14489-07 for ; Mon, 21 Jun 2004 10:08:47 +0200 (CEST) Received: from imap.rz.ufz.de (imap.rz.ufz.de [141.65.128.166]) by mr1.ufz.de (Postfix) with ESMTP id 5FB593180D6 for ; Mon, 21 Jun 2004 10:08:46 +0200 (CEST) Received: from ufz.de (isotop16.halle.ufz.de [141.65.97.147]) by imap.rz.ufz.de (iPlanet Messaging Server 5.2 (built Feb 21 2002)) with ESMTP id <0HZN00BOTFKGW7@imap.rz.ufz.de> for pgsql-sql@postgresql.org; Mon, 21 Jun 2004 10:00:16 +0200 (CEST) Date: Mon, 21 Jun 2004 10:08:46 +0200 From: Torsten Lange Subject: Re: pivot-like transformation In-reply-to: <40D60C8B.3060609@joeconway.com> To: Joe Conway Cc: pgsql-sql@postgresql.org Message-id: <40D6978E.7040501@ufz.de> MIME-version: 1.0 Content-type: text/plain; charset=ISO-8859-1; format=flowed Content-transfer-encoding: 7BIT X-Accept-Language: de-de, de-at, de, en-us, en User-Agent: Mozilla Thunderbird 0.5 (Windows/20040207) References: <1087760651.40d5e90bbd93e@webmail.ufz.de> <40D60C8B.3060609@joeconway.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200406/187 X-Sequence-Number: 18132 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