From: | Ron <ronljohnsonjr(at)gmail(dot)com> |
---|---|
To: | pgsql-general(at)lists(dot)postgresql(dot)org |
Subject: | Converting row elements into a arrays? |
Date: | 2023-03-02 20:58:41 |
Message-ID: | 788ab733-d0d1-7791-fb22-7c2724b08816@gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
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.
From | Date | Subject | |
---|---|---|---|
Next Message | Ray O'Donnell | 2023-03-02 21:01:22 | Re: Converting row elements into a arrays? |
Previous Message | Conner Bean | 2023-03-02 20:30:41 | Dropping behavior for unique CONSTRAINTs |