diff options
author | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2011-11-25 17:56:55 -0300 |
---|---|---|
committer | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2011-11-25 18:19:18 -0300 |
commit | f717f4bca298b0a1170ff506e02142e4859c3dae (patch) | |
tree | 8b7f6094f8c4be51af2ab337f21688222e95e6be /src | |
parent | 3c0afde11a12bb3ca7c68a30ad0dedaa0d1adef5 (diff) | |
download | postgresql-f717f4bca298b0a1170ff506e02142e4859c3dae.tar.gz postgresql-f717f4bca298b0a1170ff506e02142e4859c3dae.zip |
Fix unvalidated check constraints on domains, too
Same bug as reported by Thom Brown for check constraints on tables: the
constraint must be dumped separately from the domain, otherwise it is
restored before the data and thus prevents potentially-violating data
from being loaded in the first place.
Per Dean Rasheed
Diffstat (limited to 'src')
-rw-r--r-- | src/bin/pg_dump/pg_dump.c | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 76ff4d17e2c..e11ba4db749 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -4867,16 +4867,27 @@ getDomainConstraints(TypeInfo *tyinfo) query = createPQExpBuffer(); - if (g_fout->remoteVersion >= 70400) + if (g_fout->remoteVersion >= 90100) + appendPQExpBuffer(query, "SELECT tableoid, oid, conname, " + "pg_catalog.pg_get_constraintdef(oid) AS consrc, " + "convalidated " + "FROM pg_catalog.pg_constraint " + "WHERE contypid = '%u'::pg_catalog.oid " + "ORDER BY conname", + tyinfo->dobj.catId.oid); + + else if (g_fout->remoteVersion >= 70400) appendPQExpBuffer(query, "SELECT tableoid, oid, conname, " - "pg_catalog.pg_get_constraintdef(oid) AS consrc " + "pg_catalog.pg_get_constraintdef(oid) AS consrc, " + "true as convalidated " "FROM pg_catalog.pg_constraint " "WHERE contypid = '%u'::pg_catalog.oid " "ORDER BY conname", tyinfo->dobj.catId.oid); else appendPQExpBuffer(query, "SELECT tableoid, oid, conname, " - "'CHECK (' || consrc || ')' AS consrc " + "'CHECK (' || consrc || ')' AS consrc, " + "true as convalidated " "FROM pg_catalog.pg_constraint " "WHERE contypid = '%u'::pg_catalog.oid " "ORDER BY conname", @@ -4899,6 +4910,8 @@ getDomainConstraints(TypeInfo *tyinfo) for (i = 0; i < ntups; i++) { + bool validated = PQgetvalue(res, i, 4)[0] == 't'; + constrinfo[i].dobj.objType = DO_CONSTRAINT; constrinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid)); constrinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid)); @@ -4914,14 +4927,18 @@ getDomainConstraints(TypeInfo *tyinfo) constrinfo[i].condeferrable = false; constrinfo[i].condeferred = false; constrinfo[i].conislocal = true; - constrinfo[i].separate = false; + + constrinfo[i].separate = !validated; /* * Make the domain depend on the constraint, ensuring it won't be - * output till any constraint dependencies are OK. + * output till any constraint dependencies are OK. If the constraint + * has not been validated, it's going to be dumped after the domain + * anyway, so this doesn't matter. */ - addObjectDependency(&tyinfo->dobj, - constrinfo[i].dobj.dumpId); + if (validated) + addObjectDependency(&tyinfo->dobj, + constrinfo[i].dobj.dumpId); } PQclear(res); |