sql - How to join a view on an array_agg column in Postgresql? -


i'm searching syntax join view array_agg column.

view:

create view sampleview select groupid, array_agg(akey) keyarray sampletable group groupid; 

now want this:

select s.groupid, a.somedata sampleview s join anothertable on a.akey in s.keyarray; 

error message:

error:  syntax error @ or near "s" line 3: join anothertable on a.akey in s.keyarray; 

either syntax wrong (most likely) or not possible. don't believe not possible if asking alternative option.

expected output pseudo query above (with testing code):

 groupid | somedata  ---------+----------        1 | foo        1 | bar        2 | monkey (3 rows) 

testing code:

create table sampletable (groupid int not null, akey int not null); create table anothertable (akey int not null, somedata varchar(20)); create view sampleview select groupid, array_agg(akey) keyarray sampletable group groupid; insert sampletable values(1,20),(1,22),(2,33); insert anothertable values(20, 'foo'),(22,'bar'),(33,'monkey'); 

select s.groupid, a.somedata sampleview s join anothertable on a.akey = any(s.keyarray); 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -