Re: [HACKERS] Finding primary keys in a table
От | Bruce Momjian |
---|---|
Тема | Re: [HACKERS] Finding primary keys in a table |
Дата | |
Msg-id | 199807201544.LAA02008@candle.pha.pa.us обсуждение исходный текст |
Ответ на | Finding primary keys in a table (darcy@druid.net (D'Arcy J.M. Cain)) |
Ответы |
Re: [HACKERS] Finding primary keys in a table
|
Список | 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 по дате отправления: