pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ron <ronljohnsonjr@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: Converting row elements into a arrays?
Date: Thu, 2 Mar 2023 14:58:41 -0600
Message-ID: <788ab733-d0d1-7791-fb22-7c2724b08816@gmail.com> (raw)

Postgresql 12.13

Given the sample below, I'm looking for how to generate this output.  It's 
like GROUP BY, but generating an array instead of an aggreate number.
  f1 | f2_array
----+---------
1 | {1,2,3}
   2 | {1,2,3,4}
   3 | {1,2}

The ultimate goal is to somehow use pg_index.indkey to get column names from 
pg_attribute.

create table foo (f1 int, f2 int);
insert into foo values (1, 1);
insert into foo values (1, 2);
insert into foo values (1, 3);
insert into foo values (2, 1);
insert into foo values (2, 2);
insert into foo values (2, 3);
insert into foo values (2, 4);
insert into foo values (3, 1);
insert into foo values (3, 2);

select * from foo order by f1, f2;
  f1 | f2
----+----
   1 |  1
   1 |  2
   1 |  3
   2 |  1
   2 |  2
   2 |  3
   2 |  4
   3 |  1
   3 |  2
(9 rows)



-- 
Born in Arizona, moved to Babylonia.





view thread (11+ messages)  latest in thread

Message-ID: <788ab733-d0d1-7791-fb22-7c2724b08816@gmail.com>
Permalink:  ../788ab733-d0d1-7791-fb22-7c2724b08816@gmail.com/
Also on:    postgresql.org/message-id/788ab733-d0d1-7791-fb22-7c2724b08816@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: ronljohnsonjr@gmail.com
  Subject: Re: Converting row elements into a arrays?
  In-Reply-To: <788ab733-d0d1-7791-fb22-7c2724b08816@gmail.com>
  References: <788ab733-d0d1-7791-fb22-7c2724b08816@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox