Skip site navigation (1) Skip section navigation (2)

query to select the table primary key column name

From: Düster Horst <Horst(dot)Duester(at)bd(dot)so(dot)ch>
To: "'pgsql-admin(at)postgresql(dot)org'" <pgsql-admin(at)postgresql(dot)org>
Subject: query to select the table primary key column name
Date: 2006-01-31 16:48:27
Message-ID: 5B025B1F39D6D4119F5700508BEEEC6603DE3FCC@srsofaioi4546.ktso.ch (view raw or flat)
Thread:
Lists: pgsql-admin
I'm looking out for a system catalog query to select the primary key column
name for a specific table. With the following query I only get the name of
the primary key itself. How do I get the primary key column name???

select pg_constraint.*,pg_index.indisprimary
from pg_constraint,pg_namespace, pg_class, pg_index
where pg_namespace.nspname='public'
  and pg_namespace.oid=c.connamespace
  and pg_class.relname='new_layer'
  and pg_class.oid=c.conrelid
  and pg_class.oid=pg_index.indrelid
  and c.contype='p'

I'll appeciate any help.

with best regards

Dr. Horst Düster 

Kanton Solothurn 
Amt für Geoinformation
Abteilung SO!GIS Koordination
Rötistrasse 4
CH-4501 Solothurn 

Tel.: ++41 (0)32 627 25 32 
Fax: ++41 (0)32 627 22 14

horst(dot)duester(at)bd(dot)so(dot)ch 
www.sogis.so.ch


Responses

pgsql-admin by date

Next:From: Uwe C. SchroederDate: 2006-01-31 18:28:42
Subject: Re: query to select the table primary key column name
Previous:From: Tom LaneDate: 2006-01-31 14:36:12
Subject: Re: Vacuum - Out of memory

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group