From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Rob Sargent <robjsargent(at)gmail(dot)com> |
Cc: | pgsql-sql <pgsql-sql(at)lists(dot)postgresql(dot)org> |
Subject: | Re: access sub elements using any() |
Date: | 2022-11-01 00:50:06 |
Message-ID: | 1046906.1667263806@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Rob Sargent <robjsargent(at)gmail(dot)com> writes:
> Given an array of arrays ( e.g. v = {{1,'a'},{2,'b'},{3,'c'},{2,'d'}} )
> is it possible, in plain sql, to access the first element of the listed
> arrays using the IN function?
If it's actually a 2-D array, and not an array-of-composite which is
what your sample data seems to suggest, then array slicing might help:
regression=# select ('{{1,2},{3,4},{5,6}}'::int[])[:][1];
int4
---------------
{{1},{3},{5}}
(1 row)
regression=# select 2 = any (('{{1,2},{3,4},{5,6}}'::int[])[:][1]);
?column?
----------
f
(1 row)
regression=# select 3 = any (('{{1,2},{3,4},{5,6}}'::int[])[:][1]);
?column?
----------
t
(1 row)
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Ankit Kumar Pandey | 2022-11-27 16:08:33 | [QUESTION] Window function with partition by and order by |
Previous Message | Rob Sargent | 2022-10-31 22:40:20 | Re: access sub elements using any() |