Re: How to retrieve the comment for a constraint? - Mailing list pgsql-general

From Tom Lane
Subject Re: How to retrieve the comment for a constraint?
Date
Msg-id 26656.1111676724@sss.pgh.pa.us
Whole thread Raw
In response to How to retrieve the comment for a constraint?  (Wolfgang Drotschmann <drotschm@fgan.de>)
List pgsql-general
Wolfgang Drotschmann <drotschm@fgan.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

pgsql-general by date:

Previous
From: "Joshua D. Drake"
Date:
Subject: Re: Questions regarding interaction of stored functions
Next
From: Tom Lane
Date:
Subject: Re: Good Books