pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Rob Sargent <robjsargent@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: Converting row elements into a arrays?
Date: Thu, 2 Mar 2023 14:45:49 -0700
Message-ID: <e994b049-93f1-d739-e74c-ecd29bbbe4c5@gmail.com> (raw)
In-Reply-To: <788ab733-d0d1-7791-fb22-7c2724b08816@gmail.com>
References: <788ab733-d0d1-7791-fb22-7c2724b08816@gmail.com>

On 3/2/23 13:58, Ron wrote:
> 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)
>

In which environment are you accessing that array?  psql only?

>
>






view thread (11+ messages)  latest in thread

Message-ID: <e994b049-93f1-d739-e74c-ecd29bbbe4c5@gmail.com>
Permalink:  ../e994b049-93f1-d739-e74c-ecd29bbbe4c5@gmail.com/
Also on:    postgresql.org/message-id/e994b049-93f1-d739-e74c-ecd29bbbe4c5@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: robjsargent@gmail.com
  Subject: Re: Converting row elements into a arrays?
  In-Reply-To: <e994b049-93f1-d739-e74c-ecd29bbbe4c5@gmail.com>
  References: <788ab733-d0d1-7791-fb22-7c2724b08816@gmail.com> <e994b049-93f1-d739-e74c-ecd29bbbe4c5@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