pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Chris Mair <chrisnospam@1006.org>
To: Lexington Luthor <Lexington.Luthor@gmail.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Querying constraints?
Date: Thu, 10 Aug 2006 21:25:20 +0200
Message-ID: <1155237920.5893.50.camel@dell.home.lan> (raw)
In-Reply-To: <eb7mq1$htu$1@sea.gmane.org>
References: <eb7mq1$htu$1@sea.gmane.org>


> Is is possible to query from my application whether there is a primary 
> key or unique constraint on a given table and field name(s)?

Curiously enough, I just answered a similar question on the pgsql-admin
list. Try this:

SELECT c.relname as table, r.conname as contraint_name, r.contype as
contraint_type, pg_catalog.pg_get_constraintdef(r.oid, true) as
constraint_definition FROM pg_catalog.pg_constraint r,
pg_catalog.pg_class c WHERE c.oid = r.conrelid;

Bye,
Chris

-- 

Chris Mair
http://www.1006.org





view thread (3+ messages)  latest in thread

Message-ID: <1155237920.5893.50.camel@dell.home.lan>
Permalink:  ../1155237920.5893.50.camel@dell.home.lan/
Also on:    postgresql.org/message-id/1155237920.5893.50.camel@dell.home.lan

 · 

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: chrisnospam@1006.org, Lexington.Luthor@gmail.com
  Subject: Re: Querying constraints?
  In-Reply-To: <1155237920.5893.50.camel@dell.home.lan>

* 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