Re: How to retrieve the comment for a constraint?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: drotschm(at)fgan(dot)de
Cc: PostgreSQL General <pgsql-general(at)postgresql(dot)org>
Subject: Re: How to retrieve the comment for a constraint?
Date: 2005-03-24 15:05:24
Message-ID: 26656.1111676724@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Wolfgang Drotschmann <drotschm(at)fgan(dot)de> writes:
> Now, imagine you know the name of a constraint or all of them for a given
> table, e.g. destilled via
> SELECT *
> FROM information_schema.table_constraints
> WHERE table_name = '<table_name>';
> How can I get the comment for each of these constraints?

Something like this...

regression=# alter table foo add constraint bar check(id > 0);
ALTER TABLE
regression=# comment on constraint bar on foo is 'check its positive';
COMMENT
regression=# select obj_description(oid, 'pg_constraint') from pg_constraint where conname = 'bar' and conrelid = 'foo'::regclass;
obj_description
--------------------
check its positive
(1 row)

You could join to pg_description explicitly instead of using
obj_description(), and/or join to pg_class instead of using regclass.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2005-03-24 15:10:14 Re: Good Books
Previous Message Joshua D. Drake 2005-03-24 14:59:25 Re: Questions regarding interaction of stored functions