diff options
Diffstat (limited to 'src/bin/psql/describe.c')
-rw-r--r-- | src/bin/psql/describe.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index bbe632cc792..5bfebad64d5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -3053,6 +3053,50 @@ describeOneTableDetails(const char *schemaname, } PQclear(result); } + + /* + * If verbose, print NOT NULL constraints. + */ + if (verbose) + { + printfPQExpBuffer(&buf, + "SELECT c.conname, a.attname, c.connoinherit,\n" + " c.conislocal, c.coninhcount <> 0\n" + "FROM pg_catalog.pg_constraint c JOIN\n" + " pg_catalog.pg_attribute a ON\n" + " (a.attrelid = c.conrelid AND a.attnum = c.conkey[1])\n" + "WHERE c.contype = 'n' AND\n" + " c.conrelid = '%s'::pg_catalog.regclass\n" + "ORDER BY a.attnum", + oid); + + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); + + if (tuples > 0) + printTableAddFooter(&cont, _("Not-null constraints:")); + + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + bool islocal = PQgetvalue(result, i, 3)[0] == 't'; + bool inherited = PQgetvalue(result, i, 4)[0] == 't'; + + printfPQExpBuffer(&buf, " \"%s\" NOT NULL \"%s\"%s", + PQgetvalue(result, i, 0), + PQgetvalue(result, i, 1), + PQgetvalue(result, i, 2)[0] == 't' ? + " NO INHERIT" : + islocal && inherited ? _(" (local, inherited)") : + inherited ? _(" (inherited)") : ""); + + printTableAddFooter(&cont, buf.data); + } + PQclear(result); + } } /* Get view_def if table is a view or materialized view */ |