BUG #4670: Cannot get domain constraint names from psql

Started by Alexander V. Chernikovabout 17 years ago2 messagesbugs
Jump to latest
#1Alexander V. Chernikov
melifaro@ipfw.ru

The following bug has been logged online:

Bug reference: 4670
Logged by: Alexander V. Chernikov
Email address: melifaro@ipfw.ru
PostgreSQL version: 8.3.3
Operating system: FreeBSD 7.1
Description: Cannot get domain constraint names from psql
Details:

It would be nice to see domain constraint names in \dD output of psql
utility. Without this feature the only way to delete (or modify) constraint
is to do pg_dump -s (or use something like phpgadmin) to find out constraint
name and only after that issue ALTER DOMAIN .. DROP constraint statement.
Patch for adding this functionality is quite trivial, for example:

--- bin/psql/describe.c.orig    2009-02-22 02:58:23.000000000 +0300
+++ bin/psql/describe.c 2009-02-22 03:05:54.000000000 +0300
@@ -1628,6 +1628,7 @@
                                          "            WHEN NOT t.typnotnull
AND t.typdefault IS NOT NULL THEN 'default '||t.typdefault\n"
                                          "            ELSE ''\n"
                                          "       END as \"%s\",\n"
+                                         "       r.conname as \"%s\",\n"
                        "       pg_catalog.pg_get_constraintdef(r.oid, true)
as \"%s\"\n"
                                          "FROM pg_catalog.pg_type t\n"
           "     LEFT JOIN pg_catalog.pg_namespace n ON n.oid =
t.typnamespace\n"
@@ -1637,6 +1638,7 @@
                                          _("Name"),
                                          _("Type"),
                                          _("Modifier"),
+                                         _("Constraint_name"),
                                          _("Check"));

processSQLNamePattern(pset.db, &buf, pattern, true, false,

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Alexander V. Chernikov (#1)
Re: BUG #4670: Cannot get domain constraint names from psql

"Alexander V. Chernikov" <melifaro@ipfw.ru> writes:

It would be nice to see domain constraint names in \dD output of psql
utility. Without this feature the only way to delete (or modify) constraint
is to do pg_dump -s (or use something like phpgadmin) to find out constraint
name and only after that issue ALTER DOMAIN .. DROP constraint statement.

Try
select * from information_schema.domain_constraints;

The \dD view is already too wide IMHO, no need to make it wider for this.

However, your proposed patch points out something that seems to me to be
a bug in \dD: it produces multiple rows for the same domain, if said
domain has more than one constraint. Surely that's confusing and
undesirable.

regards, tom lane