pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Roger Tannous <roger77_lb@yahoo.com>
To: pgsql-sql@postgresql.org
Subject: Re: A Table's Primary Key Listing
Date: Thu, 18 Aug 2005 09:40:57 -0700 (PDT)
Message-ID: <20050818164057.38362.qmail@web51906.mail.yahoo.com> (raw)
In-Reply-To: <20050818121844.33a09ad2.darcy@druid.net>

Thanks for your query :)

But it only shows the first of the primary keys of tables having multiple
primary keys :)

This is apparently because of the pg_index.indkey[0] thing, so how can we
manage this query in order to get all of the keys :)


Thanks in advance, 
Roger Tannous.


--- "D'Arcy J.M. Cain" <darcy@druid.net> wrote:

> On Thu, 18 Aug 2005 07:36:22 -0700 (PDT)
> Roger Tannous <roger77_lb@yahoo.com> wrote:
> > Is there any means to get a list of the Primary Keys (or simply the
> > Primary Key if there's only one :) ) for a given table using an SQL
> query
> 
> Here is what I do in PyGreSQL:
> 
> SELECT pg_namespace.nspname, pg_class.relname,pg_attribute.attname
>   FROM pg_class
> JOIN pg_namespace ON pg_namespace.oid=pg_class.relnamespace AND
>     pg_namespace.nspname NOT LIKE 'pg_%'
> JOIN pg_attribute ON pg_attribute.attrelid=pg_class.oid AND
>     pg_attribute.attisdropped='f'
> JOIN pg_index ON pg_index.indrelid=pg_class.oid AND
>     pg_index.indisprimary='t' AND
>     pg_index.indkey[0]=pg_attribute.attnum
> 
> -- 
> D'Arcy J.M. Cain <darcy@druid.net>         |  Democracy is three wolves
> http://www.druid.net/darcy/                |  and a sheep voting on
> +1 416 425 1212     (DoD#0082)    (eNTP)   |  what's for dinner.
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



view thread (13+ messages)  latest in thread

Message-ID: <20050818164057.38362.qmail@web51906.mail.yahoo.com>
Permalink:  ../20050818164057.38362.qmail@web51906.mail.yahoo.com/
Also on:    postgresql.org/message-id/20050818164057.38362.qmail@web51906.mail.yahoo.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: roger77_lb@yahoo.com
  Subject: Re: A Table's Primary Key Listing
  In-Reply-To: <20050818164057.38362.qmail@web51906.mail.yahoo.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