pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: josteinu@sylfest.hiof.no
To: pgsql-sql@postgresql.org
Subject: How to find primary keys by querying system tables
Date: 24 Oct 2001 06:51:14 -0700
Message-ID: <793204a0.0110240551.645a43b@posting.google.com> (raw)

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



view thread (2+ messages)

Message-ID: <793204a0.0110240551.645a43b@posting.google.com>
Permalink:  ../793204a0.0110240551.645a43b@posting.google.com/
Also on:    postgresql.org/message-id/793204a0.0110240551.645a43b@posting.google.com

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: josteinu@sylfest.hiof.no
  Subject: Re: How to find primary keys by querying system tables
  In-Reply-To: <793204a0.0110240551.645a43b@posting.google.com>

* 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