How to find primary keys by querying system tables

Поиск
Список
Период
Сортировка
От josteinu@sylfest.hiof.no (Jostein Ulseth)
Тема How to find primary keys by querying system tables
Дата
Msg-id 793204a0.0110240551.645a43b@posting.google.com
обсуждение исходный текст
Список pgsql-sql
Hi. 

I'm trying to write a select statement that does the following; 
select all tables in my database; 
for each table, select all columns, and tell me if the column is a
primary key
in the table. 

I've tried this by querying pg_class, pg_index and pg_attribute, but I
have a problem when I this is supposed to be "general", ie I do not
know the maximum number of columns in a primary key (I can't use
subscription of "indkey").

Is there a way of testing for membership in an int2vector-field? For
example:
select column, "prim.key" from ... where pg_attribute.attnum in
pg_index.indkey
?? 

Thanks! 

-Jostein


В списке pgsql-sql по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Cross-posting (was Re: GUID in postgres)
Следующее
От: John Hasler
Дата:
Сообщение: Re: GUID in postgres