@@ -629,6 +629,50 @@ findNotNullConstraint(Oid relid, const char *colname)
629
629
return findNotNullConstraintAttnum (relid , attnum );
630
630
}
631
631
632
+ /*
633
+ * Find and return the pg_constraint tuple that implements a validated
634
+ * not-null constraint for the given domain.
635
+ */
636
+ HeapTuple
637
+ findDomainNotNullConstraint (Oid typid )
638
+ {
639
+ Relation pg_constraint ;
640
+ HeapTuple conTup ,
641
+ retval = NULL ;
642
+ SysScanDesc scan ;
643
+ ScanKeyData key ;
644
+
645
+ pg_constraint = table_open (ConstraintRelationId , AccessShareLock );
646
+ ScanKeyInit (& key ,
647
+ Anum_pg_constraint_contypid ,
648
+ BTEqualStrategyNumber , F_OIDEQ ,
649
+ ObjectIdGetDatum (typid ));
650
+ scan = systable_beginscan (pg_constraint , ConstraintRelidTypidNameIndexId ,
651
+ true, NULL , 1 , & key );
652
+
653
+ while (HeapTupleIsValid (conTup = systable_getnext (scan )))
654
+ {
655
+ Form_pg_constraint con = (Form_pg_constraint ) GETSTRUCT (conTup );
656
+
657
+ /*
658
+ * We're looking for a NOTNULL constraint that's marked validated.
659
+ */
660
+ if (con -> contype != CONSTRAINT_NOTNULL )
661
+ continue ;
662
+ if (!con -> convalidated )
663
+ continue ;
664
+
665
+ /* Found it */
666
+ retval = heap_copytuple (conTup );
667
+ break ;
668
+ }
669
+
670
+ systable_endscan (scan );
671
+ table_close (pg_constraint , AccessShareLock );
672
+
673
+ return retval ;
674
+ }
675
+
632
676
/*
633
677
* Given a pg_constraint tuple for a not-null constraint, return the column
634
678
* number it is for.
0 commit comments