| From: | Bruce Momjian <maillist(at)candle(dot)pha(dot)pa(dot)us> | 
|---|---|
| To: | darcy(at)druid(dot)net (D'Arcy J(dot)M(dot) Cain) | 
| Cc: | pgsql-hackers(at)postgreSQL(dot)org | 
| Subject: | Re: [HACKERS] Finding primary keys in a table | 
| Date: | 1998-07-20 15:44:50 | 
| Message-ID: | 199807201544.LAA02008@candle.pha.pa.us | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | 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(at)candle(dot)pha(dot)pa(dot)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)
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Bruce Momjian | 1998-07-20 17:02:35 | exec_tlist_length | 
| Previous Message | Gene Selkov, Jr. | 1998-07-20 14:51:05 | Re: [GENERAL] Recalling previous commands at the PSQL prompt |