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

Function ATExecDropExpression

src/backend/commands/tablecmds.c:9765–9875  ·  view source on GitHub ↗

* Return the address of the affected column. */

Source from the content-addressed store, hash-verified

9763 * Return the address of the affected column.
9764 */
9765static ObjectAddress
9766ATExecDropExpression(Relation rel, const char *colName, bool missing_ok, LOCKMODE lockmode)
9767{
9768 HeapTuple tuple;
9769 Form_pg_attribute attTup;
9770 AttrNumber attnum;
9771 Relation attrelation;
9772 ObjectAddress address;
9773
9774 attrelation = table_open(AttributeRelationId, RowExclusiveLock);
9775 tuple = SearchSysCacheCopyAttName(RelationGetRelid(rel), colName);
9776 if (!HeapTupleIsValid(tuple))
9777 ereport(ERROR,
9778 (errcode(ERRCODE_UNDEFINED_COLUMN),
9779 errmsg("column \"%s\" of relation \"%s\" does not exist",
9780 colName, RelationGetRelationName(rel))));
9781
9782 attTup = (Form_pg_attribute) GETSTRUCT(tuple);
9783 attnum = attTup->attnum;
9784
9785 if (attnum <= 0)
9786 ereport(ERROR,
9787 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9788 errmsg("cannot alter system column \"%s\"",
9789 colName)));
9790
9791 if (attTup->attgenerated != ATTRIBUTE_GENERATED_STORED)
9792 {
9793 if (!missing_ok)
9794 ereport(ERROR,
9795 (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
9796 errmsg("column \"%s\" of relation \"%s\" is not a stored generated column",
9797 colName, RelationGetRelationName(rel))));
9798 else
9799 {
9800 ereport(NOTICE,
9801 (errmsg("column \"%s\" of relation \"%s\" is not a stored generated column, skipping",
9802 colName, RelationGetRelationName(rel))));
9803 heap_freetuple(tuple);
9804 table_close(attrelation, RowExclusiveLock);
9805 return InvalidObjectAddress;
9806 }
9807 }
9808
9809 attTup->attgenerated = '\0';
9810 CatalogTupleUpdate(attrelation, &tuple->t_self, tuple);
9811
9812 InvokeObjectPostAlterHook(RelationRelationId,
9813 RelationGetRelid(rel),
9814 attTup->attnum);
9815 ObjectAddressSubSet(address, RelationRelationId,
9816 RelationGetRelid(rel), attnum);
9817 heap_freetuple(tuple);
9818
9819 table_close(attrelation, RowExclusiveLock);
9820
9821 CommandCounterIncrement();
9822

Callers 1

ATExecCmdFunction · 0.85

Calls 15

table_openFunction · 0.85
heap_freetupleFunction · 0.85
table_closeFunction · 0.85
CatalogTupleUpdateFunction · 0.85
CommandCounterIncrementFunction · 0.85
RemoveAttrDefaultFunction · 0.85
ScanKeyInitFunction · 0.85
ObjectIdGetDatumFunction · 0.85
Int32GetDatumFunction · 0.85
systable_beginscanFunction · 0.85
systable_getnextFunction · 0.85

Tested by

no test coverage detected