Re: Array in nested query

From: "Ken Winter" <ken(at)sunward(dot)org>
To: "PostgreSQL pg-general List" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Array in nested query
Date: 2009-02-15 22:25:23
Message-ID: E52ADDF776BB4240A81ECFE7077A8ECA@KenIBM
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Thanks, Osvaldo and Fernando - your solution works!

> -----Original Message-----
> From: Osvaldo Kussama [mailto:osvaldo(dot)kussama(at)gmail(dot)com]
> Sent: Saturday, February 14, 2009 8:24 PM
> To: Ken Winter
> Subject: Re: [GENERAL] Array in nested query
>
> 2009/2/14 Ken Winter <ken(at)sunward(dot)org>:
> > I'm trying to look up the columns in a constraint in pg_catalog (of
> > PostgreSQL 8.0.x). I can't figure out how to "join" the elements of the
> > array that lists the 'attnum's of the columns in the table to the
> 'conkey'
> > array in the constraint definition (see
> > http://www.postgresql.org/docs/8.0/static/catalog-pg-constraint.html and
> > http://www.postgresql.org/docs/8.0/static/catalog-pg-attribute.html ).
> >
> >
> >
> > The problem is in the last line of this query:
> >
> >
> >
> > SELECT a.attname AS name
> >
> > FROM pg_catalog.pg_class t, pg_catalog.pg_attribute a
> >
> > WHERE t.oid = 3626912
> >
> > AND a.attrelid = t.oid
> >
> > AND a.attnum = any (select conkey FROM pg_catalog.pg_constraint
> WHERE
> > oid = 3708025)
> >
> >
> >
> > I have tried all the variations on this syntax that I can think of,
> after
> > plowing through all the documentation of arrays I can find in
> > http://www.postgresql.org/docs/8.0/static/index.html, and none of them
> work.
> >
>
>
> I've a similar problem.
> Try explicit cast and an extra parenthesis:
>
> SELECT a.attname AS name
> FROM pg_catalog.pg_class t, pg_catalog.pg_attribute a
> WHERE t.oid = 3626912
> AND a.attrelid = t.oid
> AND a.attnum = any ((select conkey FROM pg_catalog.pg_constraint
> WHERE oid = 3708025)::smallint[]);
>
> Osvaldo

Browse pgsql-general by date

  From Date Subject
Next Message Scott Marlowe 2009-02-15 22:29:23 Re: Running untrusted sql safely?
Previous Message Adrian Klaver 2009-02-15 22:19:13 Re: Attempting to connect