From: Bruce Momjian Date: Mon, 29 Sep 2003 18:55:56 +0000 (+0000) Subject: The brackets aren't put on the CHECK constraints properly. X-Git-Tag: REL7_4_BETA4~24 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2f98ece4de78961bbde606b03620c38e15490ddc;p=postgresql The brackets aren't put on the CHECK constraints properly. Before patch: test=# select pg_get_constraintdef(oid) from pg_constraint; pg_get_constraintdef ------------------------------------------------------------------------------------------------- CHECK (VALUE >= 0) CHECK ((((a)::text = 'asdf'::text) OR ((a)::text = 'fdsa'::text)) OR ((a)::text = 'dfd'::text)) PRIMARY KEY (b) FOREIGN KEY (a) REFERENCES test2(b) UNIQUE (b) (5 rows) test=# select pg_get_constraintdef(oid, true) from pg_constraint; pg_get_constraintdef ----------------------------------------------------------------------------------- CHECK VALUE >= 0 CHECK a::text = 'asdf'::text OR a::text = 'fdsa'::text OR a::text = 'dfd'::text PRIMARY KEY (b) FOREIGN KEY (a) REFERENCES test2(b) UNIQUE (b) (5 rows) After patch: test=# select pg_get_constraintdef(oid) from pg_constraint; pg_get_constraintdef ------------------------------------------------------------------------------------------------- CHECK (VALUE >= 0) CHECK ((((a)::text = 'asdf'::text) OR ((a)::text = 'fdsa'::text)) OR ((a)::text = 'dfd'::text)) PRIMARY KEY (b) FOREIGN KEY (a) REFERENCES test2(b) UNIQUE (b) (5 rows) test=# select pg_get_constraintdef(oid, true) from pg_constraint; pg_get_constraintdef ----------------------------------------------------------------------------------- CHECK (VALUE >= 0) ` CHECK (a::text = 'asdf'::text OR a::text = 'fdsa'::text OR a::text = 'dfd'::text) PRIMARY KEY (b) FOREIGN KEY (a) REFERENCES test2(b) UNIQUE (b) (5 rows) It's important that those brackets are there to (a) match all other constraints and (b) so that people can just copy and paste them and it will work as SQL. Christopher Kings-Lynne --- diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index d362940dc7..ccf05a14e3 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -3,7 +3,7 @@ * back to source text * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.154 2003/09/15 20:03:37 petere Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.155 2003/09/29 18:55:56 momjian Exp $ * * This software is copyrighted by Jan Wieck - Hamburg. * @@ -1056,6 +1056,10 @@ pg_get_constraintdef_worker(Oid constraintId, int prettyFlags) */ appendStringInfo(&buf, "CHECK "); + /* If we're pretty-printing we need to add brackets */ + if (prettyFlags != 0) + appendStringInfo(&buf, "("); + /* Fetch constraint source */ val = heap_getattr(tup, Anum_pg_constraint_conbin, RelationGetDescr(conDesc), &isnull); @@ -1094,6 +1098,10 @@ pg_get_constraintdef_worker(Oid constraintId, int prettyFlags) /* Append the constraint source */ appendStringInfoString(&buf, consrc); + /* If we're pretty-printing we need to add brackets */ + if (prettyFlags != 0) + appendStringInfo(&buf, ")"); + break; } default: