Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite5da0fe

Browse files
committed
Catalog domain not-null constraints
This applies the explicit catalog representation of not-nullconstraints introduced byb0e96f3 for table constraints also todomain 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 parentc9c260d commite5da0fe

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_identifierAS constraint_catalog,
446446
rs.nspname::information_schema.sql_identifierAS constraint_schema,
447447
con.conname::information_schema.sql_identifierAS constraint_name,
448-
pg_catalog.format('%s IS NOT NULL',at.attname)::information_schema.character_dataAS check_clause
448+
pg_catalog.format('%s IS NOT NULL',coalesce(at.attname,'VALUE'))::information_schema.character_dataAS check_clause
449449
FROM pg_constraint con
450450
LEFT JOIN pg_namespace rsONrs.oid=con.connamespace
451451
LEFT JOIN pg_class cONc.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
returnfindNotNullConstraintAttnum(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(Oidtypid)
638+
{
639+
Relationpg_constraint;
640+
HeapTupleconTup,
641+
retval=NULL;
642+
SysScanDescscan;
643+
ScanKeyDatakey;
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_constraintcon= (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+
returnretval;
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)

[8]ページ先頭

©2009-2025 Movatter.jp