Re: access sub elements using any() - Mailing list pgsql-sql

From Tom Lane
Subject Re: access sub elements using any()
Date
Msg-id 1046906.1667263806@sss.pgh.pa.us
Whole thread Raw
In response to access sub elements using any()  (Rob Sargent <robjsargent@gmail.com>)
List pgsql-sql
Rob Sargent <robjsargent@gmail.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



pgsql-sql by date:

Previous
From: Rob Sargent
Date:
Subject: Re: access sub elements using any()
Next
From: Ankit Kumar Pandey
Date:
Subject: [QUESTION] Window function with partition by and order by