summaryrefslogtreecommitdiff
path: root/src/bin/psql/describe.c
diff options
context:
space:
mode:
authorAlvaro Herrera <alvherre@alvh.no-ip.org>2011-12-05 15:10:18 -0300
committerAlvaro Herrera <alvherre@alvh.no-ip.org>2011-12-19 17:30:23 -0300
commit61d81bd28dbec65a6b144e0cd3d0bfe25913c3ac (patch)
treebc99d53c06bed6dcc146f7eb97babba998eb5e1d /src/bin/psql/describe.c
parent92203624934095163f8b57b5b3d7bbd2645da2c8 (diff)
Allow CHECK constraints to be declared ONLY
This makes them enforceable only on the parent table, not on children tables. This is useful in various situations, per discussion involving people bitten by the restrictive behavior introduced in 8.4. Message-Id: 8762mp93iw.fsf@comcast.net CAFaPBrSMMpubkGf4zcRL_YL-AERUbYF_-ZNNYfb3CVwwEqc9TQ@mail.gmail.com Authors: Nikhil Sontakke, Alex Hunsaker Reviewed by Robert Haas and myself
Diffstat (limited to 'src/bin/psql/describe.c')
-rw-r--r--src/bin/psql/describe.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c
index dcafdd2c1ae..b6aeae22e5d 100644
--- a/src/bin/psql/describe.c
+++ b/src/bin/psql/describe.c
@@ -1781,12 +1781,20 @@ describeOneTableDetails(const char *schemaname,
/* print table (and column) check constraints */
if (tableinfo.checks)
{
+ char *is_only;
+
+ if (pset.sversion >= 90200)
+ is_only = "r.conisonly";
+ else
+ is_only = "false AS conisonly";
+
printfPQExpBuffer(&buf,
- "SELECT r.conname, "
+ "SELECT r.conname, %s, "
"pg_catalog.pg_get_constraintdef(r.oid, true)\n"
"FROM pg_catalog.pg_constraint r\n"
- "WHERE r.conrelid = '%s' AND r.contype = 'c'\nORDER BY 1;",
- oid);
+ "WHERE r.conrelid = '%s' AND r.contype = 'c'\n"
+ "ORDER BY 2 DESC, 1;",
+ is_only, oid);
result = PSQLexec(buf.data, false);
if (!result)
goto error_return;
@@ -1799,9 +1807,10 @@ describeOneTableDetails(const char *schemaname,
for (i = 0; i < tuples; i++)
{
/* untranslated contraint name and def */
- printfPQExpBuffer(&buf, " \"%s\" %s",
+ printfPQExpBuffer(&buf, " \"%s\"%s%s",
PQgetvalue(result, i, 0),
- PQgetvalue(result, i, 1));
+ (strcmp(PQgetvalue(result, i, 1), "t") == 0) ? " (ONLY) ":" ",
+ PQgetvalue(result, i, 2));
printTableAddFooter(&cont, buf.data);
}