pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: "D'Arcy" "J.M." Cain <darcy@druid.net>
To: stuart@ludwig.ucl.ac.uk
Cc: Frederic.De.Leersnijder@pandora.be
Cc: pgsql-sql@postgreSQL.org
Subject: Re: [SQL] database design SQL prob.
Date: Sat, 24 Jul 1999 07:49:38 -0400 (EDT)
Message-ID: <m1180J8-0000bFC@druid.net> (raw)
In-Reply-To: <v04020a00b3bddd224bc2@[128.40.242.190]>

Thus spake Stuart Rison
> Currently, in postgreSQL, primary keys are created as a UNIQUE index on the
> field(s) that form the primary key.
> 
> This means that there is no difference between explicitely declaring a
> PRIMARY KEY in your table definition or using the CREATE UNIQUE INDEX
> command.

Not completely accurate.  Create some tables using both methods then
run the following query.

SELECT  pg_class.relname, pg_attribute.attname
    FROM pg_class, pg_attribute, pg_index
    WHERE pg_class.oid = pg_attribute.attrelid AND
        pg_class.oid = pg_index.indrelid AND
        pg_index.indkey[0] = pg_attribute.attnum AND
        pg_index.indisprimary = 't';

This will give you a list of the primary keys if you declare them as
primary at creation time.  The ones created with just a unique index
won't be displayed.

While I am on the subject, anyone know how to enhance the above query
to display all the fields when a complex primary key is defined?  The
above assumes that all primary keys are one field per table.

-- 
D'Arcy J.M. Cain <darcy@{druid|vex}.net>   |  Democracy is three wolves
http://www.druid.net/darcy/                |  and a sheep voting on
+1 416 424 2871     (DoD#0082)    (eNTP)   |  what's for dinner.



view thread (7+ messages)  latest in thread

Message-ID: <m1180J8-0000bFC@druid.net>
Permalink:  ../m1180J8-0000bFC@druid.net/
Also on:    postgresql.org/message-id/m1180J8-0000bFC@druid.net

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: darcy@druid.net, stuart@ludwig.ucl.ac.uk, Frederic.De.Leersnijder@pandora.be
  Subject: Re: [SQL] database design SQL prob.
  In-Reply-To: <m1180J8-0000bFC@druid.net>
  References: <v04020a00b3bddd224bc2@[128.40.242.190]> <m1180J8-0000bFC@druid.net>

* 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