How to retrieve the comment for a constraint?

From: Wolfgang Drotschmann <drotschm(at)fgan(dot)de>
To: PostgreSQL General <pgsql-general(at)postgresql(dot)org>
Subject: How to retrieve the comment for a constraint?
Date: 2005-03-24 14:18:56
Message-ID: 4242CC50.60901@fgan.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hallo all,

using at least PostgreSQL 7.4.2, one can use the command
COMMENT ON CONSTRAINT <constraint_name> ON <table_name>;
to document a constraint defined via
CONSTRAINT <constraint_name> ...
in the context of a table.

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?

I mean, I can query pg_catalog.pg_description with
SELECT *
FROM pg_description
WHERE description ~ '<Begin of comment> *';
and get the tuple
objoid | classoid | objsubid | description
with the string I want to extract. I can see that it is there.

In short... Given names of schema, table and constraint, how can I get the
description out of pg_catalog.pg_description?
Do I overlook something in the forest of system catalogs, its OIDs, the
information schema...?

Thank you!

Best regards,
Wolfgang

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Robert Treat 2005-03-24 14:44:09 Re: Good Books
Previous Message Alvaro Herrera 2005-03-24 14:13:10 Re: Good Books