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 20E3ED1B188 for ; Sun, 20 Jun 2004 16:44:24 -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 31297-05 for ; Sun, 20 Jun 2004 19:44:15 +0000 (GMT) Received: from mr1.ufz.de (mr1.ufz.de [141.65.7.22]) by svr1.postgresql.org (Postfix) with ESMTP id 15938D1B1CB for ; Sun, 20 Jun 2004 16:44:12 -0300 (ADT) Received: from localhost (localhost.localdomain [127.0.0.1]) by localhost (Postfix) with ESMTP id 340643180FB for ; Sun, 20 Jun 2004 21:44:13 +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 28767-10 for ; Sun, 20 Jun 2004 21:44:11 +0200 (CEST) Received: from localhost (webmail.ufz.de [141.65.7.24]) by mr1.ufz.de (Postfix) with ESMTP id C4F663180D4 for ; Sun, 20 Jun 2004 21:44:11 +0200 (CEST) Received: from A0f8e.a.pppool.de (A0f8e.a.pppool.de [213.6.15.142]) by webmail.ufz.de (IMP) with HTTP for ; Sun, 20 Jun 2004 21:44:11 +0200 Message-ID: <1087760651.40d5e90bbd93e@webmail.ufz.de> Date: Sun, 20 Jun 2004 21:44:11 +0200 From: Torsten Lange To: pgsql-sql@postgresql.org Subject: pivot-like transformation MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit User-Agent: Internet Messaging Program (IMP) 3.2.1 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.1 tagged_above=0.0 required=5.0 tests=RCVD_IN_SORBS X-Spam-Level: X-Archive-Number: 200406/170 X-Sequence-Number: 18115 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 My first attempts to only give back the original table within a function failed. There are tons of examples to select one value into a variable... But for more I browsed through the net and my book but I couldn't find anything that works. I'm new to PL/PgSQL. Could anyone show me a _very_simple_ example of how to to read (the columns I like) from a table and return the columns (I like) using tablename%rowtype and an other possiblity if exists. 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? Thank you, Torsten