pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Querying constraints?
3+ messages / 2 participants
[nested] [flat]

* Querying constraints?
@ 2006-08-07 15:38 Lexington Luthor <Lexington.Luthor@gmail.com>
  2006-08-10 19:25 ` Re: Querying constraints? Chris Mair <chrisnospam@1006.org>
  0 siblings, 1 reply; 3+ messages in thread

From: Lexington Luthor @ 2006-08-07 15:38 UTC (permalink / raw)
  To: pgsql-sql

Hi,

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)?

Thanks
LL




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Querying constraints?
  2006-08-07 15:38 Querying constraints? Lexington Luthor <Lexington.Luthor@gmail.com>
@ 2006-08-10 19:25 ` Chris Mair <chrisnospam@1006.org>
  2006-08-10 19:27   ` Re: Querying constraints? Chris Mair <chrisnospam@1006.org>
  0 siblings, 1 reply; 3+ messages in thread

From: Chris Mair @ 2006-08-10 19:25 UTC (permalink / raw)
  To: Lexington Luthor <Lexington.Luthor@gmail.com>; +Cc: pgsql-sql


> 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





^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Querying constraints?
  2006-08-07 15:38 Querying constraints? Lexington Luthor <Lexington.Luthor@gmail.com>
  2006-08-10 19:25 ` Re: Querying constraints? Chris Mair <chrisnospam@1006.org>
@ 2006-08-10 19:27   ` Chris Mair <chrisnospam@1006.org>
  0 siblings, 0 replies; 3+ messages in thread

From: Chris Mair @ 2006-08-10 19:27 UTC (permalink / raw)
  To: Lexington Luthor <Lexington.Luthor@gmail.com>; +Cc: pgsql-sql


> 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;

I forgot to mention, it's tested on 8.1...

Bye, Chris.

-- 

Chris Mair
http://www.1006.org





^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2006-08-10 19:27 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-08-07 15:38 Querying constraints? Lexington Luthor <Lexington.Luthor@gmail.com>
2006-08-10 19:25 ` Chris Mair <chrisnospam@1006.org>
2006-08-10 19:27   ` Chris Mair <chrisnospam@1006.org>

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