Re: About primary keys.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: David BOURIAUD <david(dot)bouriaud(at)ac-rouen(dot)fr>
Cc: "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: About primary keys.
Date: 2001-06-19 14:38:45
Message-ID: 22741.992961525@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

David BOURIAUD <david(dot)bouriaud(at)ac-rouen(dot)fr> writes:
>> Caveat: Does not work for complex primary keys.

> Thanks, but that is my problem actually !

Here's a rather brute-force approach:

select relname,
(select attname from pg_attribute where
attrelid = c.oid and attnum = indkey[0]),
(select attname from pg_attribute where
attrelid = c.oid and attnum = indkey[1]),
(select attname from pg_attribute where
attrelid = c.oid and attnum = indkey[2]),
(select attname from pg_attribute where
attrelid = c.oid and attnum = indkey[3])
from pg_class c, pg_index i
where c.oid = indrelid and indisprimary;

You can carry this out to however many key columns you want to
deal with. The sub-selects will yield NULLs for the columns after
the last key column of a particular index, which is just what you
want here.

regards, tom lane

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Najm Hashmi 2001-06-19 15:46:02 Extracting date from epoche
Previous Message David BOURIAUD 2001-06-19 14:38:44 Re: About primary keys.