Re: array indizes in SQL

From: Rodrigo De León <rdeleonp(at)gmail(dot)com>
To: "Hans-Peter Oeri" <hp(at)oeri(dot)ch>
Cc: ListaPostgre <pgsql-novice(at)postgresql(dot)org>
Subject: Re: array indizes in SQL
Date: 2007-11-12 13:48:58
Message-ID: a55915760711120548m138c869fs5574774fa461e86f@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On 11/12/07, Hans-Peter Oeri <hp(at)oeri(dot)ch> wrote:

...

> E.g. to get the pk fields I wrote:
>
> SELECT
> a.attname AS "primarykey"
> FROM
> generate_series(1,5) as i, -- yuck!!
> pg_catalog.pg_attribute as a,
> pg_catalog.pg_constraint as o
> WHERE
> o.conkey[i] = a.attnum
> AND a.attrelid = o.conrelid
> AND o.contype = 'p'
> AND o.conrelid = CAST( ? AS regclass )
> ORDER BY
> i ASC

...

> Is there a better way to "decompose" an array? (that I didn't find)

SELECT a.attname AS "primarykey"
FROM pg_catalog.pg_attribute AS a,
pg_catalog.pg_constraint AS o
WHERE a.attnum = ANY (o.conkey)
AND a.attrelid = o.conrelid
AND o.contype = 'p'
AND o.conrelid = CAST ( ? AS regclass)
ORDER BY a.attnum ASC

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Hans-Peter Oeri 2007-11-12 14:45:46 Re: array indizes in SQL
Previous Message Hans-Peter Oeri 2007-11-12 07:26:09 array indizes in SQL