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

Function ATExecDropIdentity

src/backend/commands/tablecmds.c:9645–9714  ·  view source on GitHub ↗

* ALTER TABLE ALTER COLUMN DROP IDENTITY * * Return the address of the affected column. */

Source from the content-addressed store, hash-verified

9643 * Return the address of the affected column.
9644 */
9645static ObjectAddress
9646ATExecDropIdentity(Relation rel, const char *colName, bool missing_ok, LOCKMODE lockmode)
9647{
9648 HeapTuple tuple;
9649 Form_pg_attribute attTup;
9650 AttrNumber attnum;
9651 Relation attrelation;
9652 ObjectAddress address;
9653 Oid seqid;
9654 ObjectAddress seqaddress;
9655
9656 attrelation = table_open(AttributeRelationId, RowExclusiveLock);
9657 tuple = SearchSysCacheCopyAttName(RelationGetRelid(rel), colName);
9658 if (!HeapTupleIsValid(tuple))
9659 ereport(ERROR,
9660 (errcode(ERRCODE_UNDEFINED_COLUMN),
9661 errmsg("column \"%s\" of relation \"%s\" does not exist",
9662 colName, RelationGetRelationName(rel))));
9663
9664 attTup = (Form_pg_attribute) GETSTRUCT(tuple);
9665 attnum = attTup->attnum;
9666
9667 if (attnum <= 0)
9668 ereport(ERROR,
9669 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9670 errmsg("cannot alter system column \"%s\"",
9671 colName)));
9672
9673 if (!attTup->attidentity)
9674 {
9675 if (!missing_ok)
9676 ereport(ERROR,
9677 (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
9678 errmsg("column \"%s\" of relation \"%s\" is not an identity column",
9679 colName, RelationGetRelationName(rel))));
9680 else
9681 {
9682 ereport((Gp_role == GP_ROLE_EXECUTE) ? DEBUG1 : NOTICE,
9683 (errmsg("column \"%s\" of relation \"%s\" is not an identity column, skipping",
9684 colName, RelationGetRelationName(rel))));
9685 heap_freetuple(tuple);
9686 table_close(attrelation, RowExclusiveLock);
9687 return InvalidObjectAddress;
9688 }
9689 }
9690
9691 attTup->attidentity = '\0';
9692 CatalogTupleUpdate(attrelation, &tuple->t_self, tuple);
9693
9694 InvokeObjectPostAlterHook(RelationRelationId,
9695 RelationGetRelid(rel),
9696 attTup->attnum);
9697 ObjectAddressSubSet(address, RelationRelationId,
9698 RelationGetRelid(rel), attnum);
9699 heap_freetuple(tuple);
9700
9701 table_close(attrelation, RowExclusiveLock);
9702

Callers 1

ATExecCmdFunction · 0.85

Calls 11

table_openFunction · 0.85
heap_freetupleFunction · 0.85
table_closeFunction · 0.85
CatalogTupleUpdateFunction · 0.85
getIdentitySequenceFunction · 0.85
CommandCounterIncrementFunction · 0.85
performDeletionFunction · 0.85
errcodeFunction · 0.50
errmsgFunction · 0.50

Tested by

no test coverage detected