Skip to content

Commit f717f4b

Browse files
committed
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
1 parent 3c0afde commit f717f4b

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

src/bin/pg_dump/pg_dump.c

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4867,16 +4867,27 @@ getDomainConstraints(TypeInfo *tyinfo)
48674867

48684868
query = createPQExpBuffer();
48694869

4870-
if (g_fout->remoteVersion >= 70400)
4870+
if (g_fout->remoteVersion >= 90100)
4871+
appendPQExpBuffer(query, "SELECT tableoid, oid, conname, "
4872+
"pg_catalog.pg_get_constraintdef(oid) AS consrc, "
4873+
"convalidated "
4874+
"FROM pg_catalog.pg_constraint "
4875+
"WHERE contypid = '%u'::pg_catalog.oid "
4876+
"ORDER BY conname",
4877+
tyinfo->dobj.catId.oid);
4878+
4879+
else if (g_fout->remoteVersion >= 70400)
48714880
appendPQExpBuffer(query, "SELECT tableoid, oid, conname, "
4872-
"pg_catalog.pg_get_constraintdef(oid) AS consrc "
4881+
"pg_catalog.pg_get_constraintdef(oid) AS consrc, "
4882+
"true as convalidated "
48734883
"FROM pg_catalog.pg_constraint "
48744884
"WHERE contypid = '%u'::pg_catalog.oid "
48754885
"ORDER BY conname",
48764886
tyinfo->dobj.catId.oid);
48774887
else
48784888
appendPQExpBuffer(query, "SELECT tableoid, oid, conname, "
4879-
"'CHECK (' || consrc || ')' AS consrc "
4889+
"'CHECK (' || consrc || ')' AS consrc, "
4890+
"true as convalidated "
48804891
"FROM pg_catalog.pg_constraint "
48814892
"WHERE contypid = '%u'::pg_catalog.oid "
48824893
"ORDER BY conname",
@@ -4899,6 +4910,8 @@ getDomainConstraints(TypeInfo *tyinfo)
48994910

49004911
for (i = 0; i < ntups; i++)
49014912
{
4913+
bool validated = PQgetvalue(res, i, 4)[0] == 't';
4914+
49024915
constrinfo[i].dobj.objType = DO_CONSTRAINT;
49034916
constrinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
49044917
constrinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
@@ -4914,14 +4927,18 @@ getDomainConstraints(TypeInfo *tyinfo)
49144927
constrinfo[i].condeferrable = false;
49154928
constrinfo[i].condeferred = false;
49164929
constrinfo[i].conislocal = true;
4917-
constrinfo[i].separate = false;
4930+
4931+
constrinfo[i].separate = !validated;
49184932

49194933
/*
49204934
* Make the domain depend on the constraint, ensuring it won't be
4921-
* output till any constraint dependencies are OK.
4935+
* output till any constraint dependencies are OK. If the constraint
4936+
* has not been validated, it's going to be dumped after the domain
4937+
* anyway, so this doesn't matter.
49224938
*/
4923-
addObjectDependency(&tyinfo->dobj,
4924-
constrinfo[i].dobj.dumpId);
4939+
if (validated)
4940+
addObjectDependency(&tyinfo->dobj,
4941+
constrinfo[i].dobj.dumpId);
49254942
}
49264943

49274944
PQclear(res);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy