Re: need help with query, how to fold select result to array? - Mailing list pgsql-general

From Sam Mason
Subject Re: need help with query, how to fold select result to array?
Date
Msg-id 20100112144144.GH5407@samason.me.uk
Whole thread Raw
In response to Re: need help with query, how to fold select result to array?  (Sergey Levchenko <sector119@gmail.com>)
List pgsql-general
On Tue, Jan 12, 2010 at 04:06:20PM +0200, Sergey Levchenko wrote:
> but I have to fold it in multi-dimensional, array like {{71629130,
> 15518, 0}, {2668722, 616, 0}} ?
> but it's not possible to pass more then one argument to the array_agg
> function :/

Tuples work fine.  Multidimensional arrays are awfully complicated and
it's generally better to stay away from them, arrays of tuples make more
sense.  Maybe something like:

  CREATE TYPE meterreading (
    meter_id    INT,
    org_reading NUMERIC,
    reading     NUMERIC
  );
  SELECT office_id, serial, commit_date, service_id,
    array_agg(row(meter_id, organization_reading, reading)::meterreading) AS readings
  FROM meter_readings;


--
  Sam  http://samason.me.uk/

pgsql-general by date:

Previous
From: Grzegorz Jaśkiewicz
Date:
Subject: Re: How to find column type
Next
From: Adrian Klaver
Date:
Subject: Re: Weird EXECUTE ... USING behaviour