@@ -152,6 +152,10 @@ static void dump_fk_constraint(HeapTuple tup, Oid relid_dst,
152
152
StringInfo buf );
153
153
static void dump_check_constraint (Oid relid_dst , const char * relname_dst ,
154
154
HeapTuple tup , StringInfo buf );
155
+ #if PG_VERSION_NUM >= 180000
156
+ static void dump_null_constraint (Oid relid_dst , const char * relname_dst ,
157
+ HeapTuple tup , StringInfo buf );
158
+ #endif
155
159
static void dump_constraint_common (const char * nsp , const char * relname ,
156
160
Form_pg_constraint con , StringInfo buf );
157
161
static int decompile_column_index_array (Datum column_index_array , Oid relId ,
@@ -2916,13 +2920,15 @@ copy_constraints(Oid relid_dst, const char *relname_dst, Oid relid_src)
2916
2920
break ;
2917
2921
}
2918
2922
2919
- /*
2920
- * TODO Is it o.k. to assume that no data type conversion can
2921
- * change the validity of NOT NULL constraint? The problem is
2922
- * that NOT NULL cannot be set NOT VALID in PG < 18. At least
2923
- * in PG >= 18 we probably should handle NOT NULL in the same
2924
- * way as FK / CHECK constraints.
2925
- */
2923
+ #if PG_VERSION_NUM >= 180000
2924
+ case CONSTRAINT_NOTNULL :
2925
+ {
2926
+ if (con -> conrelid == relid_src )
2927
+ dump_null_constraint (relid_dst , relname_dst , tuple ,
2928
+ buf );
2929
+ break ;
2930
+ }
2931
+ #endif
2926
2932
default :
2927
2933
break ;
2928
2934
}
@@ -3183,6 +3189,31 @@ dump_check_constraint(Oid relid_dst, const char *relname_dst, HeapTuple tup,
3183
3189
con -> connoinherit ? " NO INHERIT" : "" );
3184
3190
}
3185
3191
3192
+ #if PG_VERSION_NUM >= 180000
3193
+ static void
3194
+ dump_null_constraint (Oid relid_dst , const char * relname_dst ,
3195
+ HeapTuple tup , StringInfo buf )
3196
+ {
3197
+ Form_pg_constraint con = (Form_pg_constraint ) GETSTRUCT (tup );
3198
+ const char * nsp ;
3199
+ AttrNumber attnum ;
3200
+
3201
+ Assert (con -> contype == CONSTRAINT_NOTNULL );
3202
+
3203
+ nsp = get_namespace_name (relid_dst );
3204
+ dump_constraint_common (nsp , relname_dst , con , buf );
3205
+
3206
+ attnum = extractNotNullColumn (tup );
3207
+
3208
+ appendStringInfo (buf , "NOT NULL %s" ,
3209
+ quote_identifier (get_attname (con -> conrelid ,
3210
+ attnum , false)));
3211
+ if (((Form_pg_constraint ) GETSTRUCT (tup ))-> connoinherit )
3212
+ appendStringInfoString (buf , " NO INHERIT" );
3213
+
3214
+ }
3215
+ #endif
3216
+
3186
3217
static void
3187
3218
dump_constraint_common (const char * nsp , const char * relname ,
3188
3219
Form_pg_constraint con , StringInfo buf )
0 commit comments