* ALTER TABLE ALTER COLUMN DROP EXPRESSION */
| 9717 | * ALTER TABLE ALTER COLUMN DROP EXPRESSION |
| 9718 | */ |
| 9719 | static void |
| 9720 | ATPrepDropExpression(Relation rel, AlterTableCmd *cmd, bool recurse, bool recursing, LOCKMODE lockmode) |
| 9721 | { |
| 9722 | /* |
| 9723 | * Reject ONLY if there are child tables. We could implement this, but it |
| 9724 | * is a bit complicated. GENERATED clauses must be attached to the column |
| 9725 | * definition and cannot be added later like DEFAULT, so if a child table |
| 9726 | * has a generation expression that the parent does not have, the child |
| 9727 | * column will necessarily be an attlocal column. So to implement ONLY |
| 9728 | * here, we'd need extra code to update attislocal of the direct child |
| 9729 | * tables, somewhat similar to how DROP COLUMN does it, so that the |
| 9730 | * resulting state can be properly dumped and restored. |
| 9731 | */ |
| 9732 | if (!recurse && |
| 9733 | find_inheritance_children(RelationGetRelid(rel), lockmode)) |
| 9734 | ereport(ERROR, |
| 9735 | (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), |
| 9736 | errmsg("ALTER TABLE / DROP EXPRESSION must be applied to child tables too"))); |
| 9737 | |
| 9738 | /* |
| 9739 | * Cannot drop generation expression from inherited columns. |
| 9740 | */ |
| 9741 | if (!recursing) |
| 9742 | { |
| 9743 | HeapTuple tuple; |
| 9744 | Form_pg_attribute attTup; |
| 9745 | |
| 9746 | tuple = SearchSysCacheCopyAttName(RelationGetRelid(rel), cmd->name); |
| 9747 | if (!HeapTupleIsValid(tuple)) |
| 9748 | ereport(ERROR, |
| 9749 | (errcode(ERRCODE_UNDEFINED_COLUMN), |
| 9750 | errmsg("column \"%s\" of relation \"%s\" does not exist", |
| 9751 | cmd->name, RelationGetRelationName(rel)))); |
| 9752 | |
| 9753 | attTup = (Form_pg_attribute) GETSTRUCT(tuple); |
| 9754 | |
| 9755 | if (attTup->attinhcount > 0) |
| 9756 | ereport(ERROR, |
| 9757 | (errcode(ERRCODE_INVALID_TABLE_DEFINITION), |
| 9758 | errmsg("cannot drop generation expression from inherited column"))); |
| 9759 | } |
| 9760 | } |
| 9761 | |
| 9762 | /* |
| 9763 | * Return the address of the affected column. |
no test coverage detected