Skip to content

Commit e5da0fe

Browse files
committed
Catalog domain not-null constraints
This applies the explicit catalog representation of not-null constraints introduced by b0e96f3 for table constraints also to domain not-null constraints. Reviewed-by: Aleksander Alekseev <aleksander@timescale.com> Reviewed-by: jian he <jian.universality@gmail.com> Discussion: https://www.postgresql.org/message-id/flat/9ec24d7b-633d-463a-84c6-7acff769c9e8%40eisentraut.org
1 parent c9c260d commit e5da0fe

File tree

10 files changed

+386
-115
lines changed

10 files changed

+386
-115
lines changed

src/backend/catalog/information_schema.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ CREATE VIEW check_constraints AS
445445
SELECT current_database()::information_schema.sql_identifier AS constraint_catalog,
446446
rs.nspname::information_schema.sql_identifier AS constraint_schema,
447447
con.conname::information_schema.sql_identifier AS constraint_name,
448-
pg_catalog.format('%s IS NOT NULL', at.attname)::information_schema.character_data AS check_clause
448+
pg_catalog.format('%s IS NOT NULL', coalesce(at.attname, 'VALUE'))::information_schema.character_data AS check_clause
449449
FROM pg_constraint con
450450
LEFT JOIN pg_namespace rs ON rs.oid = con.connamespace
451451
LEFT JOIN pg_class c ON c.oid = con.conrelid

src/backend/catalog/pg_constraint.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,50 @@ findNotNullConstraint(Oid relid, const char *colname)
629629
return findNotNullConstraintAttnum(relid, attnum);
630630
}
631631

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+
632676
/*
633677
* Given a pg_constraint tuple for a not-null constraint, return the column
634678
* number it is for.

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