join mit Array

Wie kann ich in einem join ueber eine Tabelle iterieren ?
Annahme:
tabelle article ( id int, name )
tabelle xy (id, int , articles int[] )

in xy.articles ist also eine Liste von article.id gespeichert.
Ich würde nun gerne etwas in der Art machen:

select article.name from article where id in (select articles from xy ).

My ANY bekomme ich das auch nicht hin.
select article.name from article join xx on article. id = ANY(articles )

ging auch nicht :frowning:

ab 8.4:

test=*# select * from xy;
 id | articles
----+----------
  1 | {1,2,3}
(1 row)

test=*# select * from artikel ;
 id | name
----+------
  1 | art1
  2 | art2
  3 | art3
(3 rows)

test=*# select artikel.name from artikel where id in (select unnest(articles) from xy where id=1 );
 name
------
 art1
 art2
 art3
(3 rows)

Vorher:

CREATE OR REPLACE FUNCTION unnest(ANYARRAY) RETURNS SETOF ANYELEMENT LANGUAGE SQL AS $$SELECT $1[i] FROM generate_series(array_lower($1,1),array_upper($1,1)) i;$$;

Dann bei David dafür bedanken und weiter wie oben.

Andreas

Super, dachte eigent. sowas wie das unnest müssste es schon im Standard geben. Aber man ist ja flexibel bei PG :slight_smile:
Danke