@@ -5953,11 +5953,22 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
5953
5953
tbinfo -> dobj .name );
5954
5954
5955
5955
resetPQExpBuffer (q );
5956
- if (g_fout -> remoteVersion >= 80400 )
5956
+ if (g_fout -> remoteVersion >= 90100 )
5957
5957
{
5958
5958
appendPQExpBuffer (q , "SELECT tableoid, oid, conname, "
5959
5959
"pg_catalog.pg_get_constraintdef(oid) AS consrc, "
5960
- "conislocal "
5960
+ "conislocal, convalidated "
5961
+ "FROM pg_catalog.pg_constraint "
5962
+ "WHERE conrelid = '%u'::pg_catalog.oid "
5963
+ " AND contype = 'c' "
5964
+ "ORDER BY conname" ,
5965
+ tbinfo -> dobj .catId .oid );
5966
+ }
5967
+ else if (g_fout -> remoteVersion >= 80400 )
5968
+ {
5969
+ appendPQExpBuffer (q , "SELECT tableoid, oid, conname, "
5970
+ "pg_catalog.pg_get_constraintdef(oid) AS consrc, "
5971
+ "conislocal, true AS convalidated "
5961
5972
"FROM pg_catalog.pg_constraint "
5962
5973
"WHERE conrelid = '%u'::pg_catalog.oid "
5963
5974
" AND contype = 'c' "
@@ -5968,7 +5979,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
5968
5979
{
5969
5980
appendPQExpBuffer (q , "SELECT tableoid, oid, conname, "
5970
5981
"pg_catalog.pg_get_constraintdef(oid) AS consrc, "
5971
- "true AS conislocal "
5982
+ "true AS conislocal, true AS convalidated "
5972
5983
"FROM pg_catalog.pg_constraint "
5973
5984
"WHERE conrelid = '%u'::pg_catalog.oid "
5974
5985
" AND contype = 'c' "
@@ -5980,7 +5991,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
5980
5991
/* no pg_get_constraintdef, must use consrc */
5981
5992
appendPQExpBuffer (q , "SELECT tableoid, oid, conname, "
5982
5993
"'CHECK (' || consrc || ')' AS consrc, "
5983
- "true AS conislocal "
5994
+ "true AS conislocal, true AS convalidated "
5984
5995
"FROM pg_catalog.pg_constraint "
5985
5996
"WHERE conrelid = '%u'::pg_catalog.oid "
5986
5997
" AND contype = 'c' "
@@ -5993,7 +6004,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
5993
6004
appendPQExpBuffer (q , "SELECT tableoid, 0 AS oid, "
5994
6005
"rcname AS conname, "
5995
6006
"'CHECK (' || rcsrc || ')' AS consrc, "
5996
- "true AS conislocal "
6007
+ "true AS conislocal, true AS convalidated "
5997
6008
"FROM pg_relcheck "
5998
6009
"WHERE rcrelid = '%u'::oid "
5999
6010
"ORDER BY rcname" ,
@@ -6004,7 +6015,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
6004
6015
appendPQExpBuffer (q , "SELECT tableoid, oid, "
6005
6016
"rcname AS conname, "
6006
6017
"'CHECK (' || rcsrc || ')' AS consrc, "
6007
- "true AS conislocal "
6018
+ "true AS conislocal, true AS convalidated "
6008
6019
"FROM pg_relcheck "
6009
6020
"WHERE rcrelid = '%u'::oid "
6010
6021
"ORDER BY rcname" ,
@@ -6017,7 +6028,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
6017
6028
"(SELECT oid FROM pg_class WHERE relname = 'pg_relcheck') AS tableoid, "
6018
6029
"oid, rcname AS conname, "
6019
6030
"'CHECK (' || rcsrc || ')' AS consrc, "
6020
- "true AS conislocal "
6031
+ "true AS conislocal, true AS convalidated "
6021
6032
"FROM pg_relcheck "
6022
6033
"WHERE rcrelid = '%u'::oid "
6023
6034
"ORDER BY rcname" ,
@@ -6042,6 +6053,8 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
6042
6053
6043
6054
for (j = 0 ; j < numConstrs ; j ++ )
6044
6055
{
6056
+ bool validated = PQgetvalue (res , j , 5 )[0 ] == 't' ;
6057
+
6045
6058
constrs [j ].dobj .objType = DO_CONSTRAINT ;
6046
6059
constrs [j ].dobj .catId .tableoid = atooid (PQgetvalue (res , j , 0 ));
6047
6060
constrs [j ].dobj .catId .oid = atooid (PQgetvalue (res , j , 1 ));
@@ -6057,18 +6070,27 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
6057
6070
constrs [j ].condeferrable = false;
6058
6071
constrs [j ].condeferred = false;
6059
6072
constrs [j ].conislocal = (PQgetvalue (res , j , 4 )[0 ] == 't' );
6060
- constrs [j ].separate = false;
6073
+ /*
6074
+ * An unvalidated constraint needs to be dumped separately, so
6075
+ * that potentially-violating existing data is loaded before
6076
+ * the constraint.
6077
+ */
6078
+ constrs [j ].separate = !validated ;
6061
6079
6062
6080
constrs [j ].dobj .dump = tbinfo -> dobj .dump ;
6063
6081
6064
6082
/*
6065
6083
* Mark the constraint as needing to appear before the table
6066
6084
* --- this is so that any other dependencies of the
6067
6085
* constraint will be emitted before we try to create the
6068
- * table.
6086
+ * table. If the constraint is not validated, it will be
6087
+ * dumped after data is loaded anyway, so don't do it. (There's
6088
+ * an automatic dependency in the opposite direction anyway, so
6089
+ * don't need to add one manually here.)
6069
6090
*/
6070
- addObjectDependency (& tbinfo -> dobj ,
6071
- constrs [j ].dobj .dumpId );
6091
+ if (validated )
6092
+ addObjectDependency (& tbinfo -> dobj ,
6093
+ constrs [j ].dobj .dumpId );
6072
6094
6073
6095
/*
6074
6096
* If the constraint is inherited, this will be detected later
0 commit comments