MCPcopy Create free account
hub / github.com/apache/cloudberry / ATExecCheckNotNull

Function ATExecCheckNotNull

src/backend/commands/tablecmds.c:9304–9327  ·  view source on GitHub ↗

* ALTER TABLE ALTER COLUMN CHECK NOT NULL * * This doesn't exist in the grammar, but we generate AT_CheckNotNull * commands against the partitions of a partitioned table if the user * writes ALTER TABLE ONLY ... SET NOT NULL on the partitioned table, * or tries to create a primary key on it (which internally creates * AT_SetNotNull on the partitioned table). Such a command doesn't * allow

Source from the content-addressed store, hash-verified

9302 * For now we need only check for the presence of the flag.
9303 */
9304static void
9305ATExecCheckNotNull(AlteredTableInfo *tab, Relation rel,
9306 const char *colName, LOCKMODE lockmode)
9307{
9308 HeapTuple tuple;
9309
9310 tuple = SearchSysCacheAttName(RelationGetRelid(rel), colName);
9311
9312 if (!HeapTupleIsValid(tuple))
9313 ereport(ERROR,
9314 (errcode(ERRCODE_UNDEFINED_COLUMN),
9315 errmsg("column \"%s\" of relation \"%s\" does not exist",
9316 colName, RelationGetRelationName(rel))));
9317
9318 if (!((Form_pg_attribute) GETSTRUCT(tuple))->attnotnull)
9319 ereport(ERROR,
9320 (errcode(ERRCODE_INVALID_TABLE_DEFINITION),
9321 errmsg("constraint must be added to child tables too"),
9322 errdetail("Column \"%s\" of relation \"%s\" is not already NOT NULL.",
9323 colName, RelationGetRelationName(rel)),
9324 errhint("Do not specify the ONLY keyword.")));
9325
9326 ReleaseSysCache(tuple);
9327}
9328
9329/*
9330 * NotNullImpliedByRelConstraints

Callers 1

ATExecCmdFunction · 0.85

Calls 6

SearchSysCacheAttNameFunction · 0.85
ReleaseSysCacheFunction · 0.85
errcodeFunction · 0.50
errmsgFunction · 0.50
errdetailFunction · 0.50
errhintFunction · 0.50

Tested by

no test coverage detected