pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: David BOURIAUD <david.bouriaud@ac-rouen.fr>
Cc: pgsql-sql@postgresql.org <pgsql-sql@postgresql.org>
Subject: Re: About primary keys.
Date: Tue, 19 Jun 2001 10:38:45 -0400
Message-ID: <22741.992961525@sss.pgh.pa.us> (raw)
In-Reply-To: <3B2F4A8E.B6E07DBB@ac-rouen.fr>
References: <20010619123625.F01A21A78@druid.net>
	<3B2F4A8E.B6E07DBB@ac-rouen.fr>

David BOURIAUD <david.bouriaud@ac-rouen.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



view thread (9+ messages)  latest in thread

Message-ID: <22741.992961525@sss.pgh.pa.us>
Permalink:  ../22741.992961525@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/22741.992961525@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, david.bouriaud@ac-rouen.fr
  Subject: Re: About primary keys.
  In-Reply-To: <22741.992961525@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox