Re: [HACKERS] Finding primary keys in a table - Mailing list pgsql-hackers

From Bruce Momjian
Subject Re: [HACKERS] Finding primary keys in a table
Date
Msg-id 199807201544.LAA02008@candle.pha.pa.us
Whole thread Raw
In response to Finding primary keys in a table  (darcy@druid.net (D'Arcy J.M. Cain))
Responses Re: [HACKERS] Finding primary keys in a table
List pgsql-hackers
> I am trying to finish off my Python interface with some extra helper
> functions and I need to find the primary key in a table if it exists.
> I have two questions.
>
> Although I can't imagine doing so, will the system allow you to create
> more than one primary key on a table?  I just need to know whether I
> ned to test for multiple keys.
>
> Can someone suggest a SQL statement to pull out the primary key(s) from
> a table?
>
> Also, if multiple keys are allowed, what are people's opinions about
> using them?  Basically I am creating a get function that is defined as:
>
> def db_get(db, cl, arg, keyname = None):
>
> where db is the database handle, cl is the class, arg is either a value
> to lookup or a dictionary containing the value and keyname is the
> field to lookup which defaults to the primary key.  The question is,
> what do I do if keyname is omitted (defaults to primary) and there
> are two primary keys.  Should I just use the first one or should I
> raise an exception.  I favour the latter.

Because we just create a unique index on a PRIMARY specification, I
think any unique index on a field shows it as primary.


--
Bruce Momjian                          |  830 Blythe Avenue
maillist@candle.pha.pa.us              |  Drexel Hill, Pennsylvania 19026
  +  If your life is a hard drive,     |  (610) 353-9879(w)
  +  Christ can be your backup.        |  (610) 853-3000(h)

pgsql-hackers by date:

Previous
From: "Gene Selkov, Jr."
Date:
Subject: Re: [GENERAL] Recalling previous commands at the PSQL prompt
Next
From: Bruce Momjian
Date:
Subject: exec_tlist_length