{"record":{"id":"22e57369aace1b2c","repo":"risingwavelabs/risingwave","slug":"failed-to-drop-column-because-it-s-referenced","errorCode":null,"errorMessage":"failed to drop column \"{}\" because it's referenced by a generated column \"{}\"","messagePattern":"failed to drop column \"(.+?)\" because it's referenced by a generated column \"(.+?)\"","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/frontend/src/handler/alter_table_column.rs","lineNumber":234,"sourceCode":"\n        AlterTableOperation::DropColumn {\n            column_name,\n            if_exists,\n            cascade,\n        } => {\n            if cascade {\n                bail_not_implemented!(issue = 6903, \"drop column cascade\");\n            }\n\n            // Check if the column to drop is referenced by any generated columns.\n            for column in original_catalog.columns() {\n                if let Some(expr) = column.generated_expr() {\n                    let expr = ExprImpl::from_expr_proto(expr)?;\n                    let refs = expr.collect_input_refs(original_catalog.columns().len());\n                    for idx in refs.ones() {\n                        let refed_column = &original_catalog.columns()[idx];\n                        if refed_column.name() == column_name.real_value() {\n                            bail!(format!(\n                                \"failed to drop column \\\"{}\\\" because it's referenced by a generated column \\\"{}\\\"\",\n                                column_name,\n                                column.name()\n                            ))\n                        }\n                    }\n                }\n            }\n\n            // Locate the column by name and remove it.\n            let column_name = column_name.real_value();\n            let removed_column = columns\n                .extract_if(.., |c| c.name.real_value() == column_name)\n                .at_most_one()\n                .ok()\n                .unwrap();\n\n            if removed_column.is_some() {","sourceCodeStart":216,"sourceCodeEnd":252,"githubUrl":"https://github.com/risingwavelabs/risingwave/blob/6469eb736d691e8e9b8a419a57edd6429ca77417/src/frontend/src/handler/alter_table_column.rs#L216-L252","documentation":"Dropping a column would break a generated (computed) column whose expression references it. Before dropping, the handler walks each generated column's expression, collects the input column references, and bails if the column being dropped is among them. This protects dependent computed columns from becoming invalid.","triggerScenarios":"ALTER TABLE t DROP COLUMN c where c.name is referenced by a generated column expression (e.g. generated column defined as price*qty and dropping price or qty).","commonSituations":"Schema cleanup removing what looks like an unused column that is actually an input to a computed column; automated migrations that don't account for generated column dependencies.","solutions":["Drop the dependent generated column first, then drop the target column","Redefine the generated column so it no longer references the column, then drop","Keep the column if the generated column is still needed"],"exampleFix":"-- before\nALTER TABLE t DROP COLUMN price; -- referenced by generated col total = price*qty\n-- after\nALTER TABLE t DROP COLUMN total;\nALTER TABLE t DROP COLUMN price;","handlingStrategy":"validation","validationCode":"SELECT dependent_column FROM rw_catalog.rw_columns\nWHERE relation_id = (SELECT id FROM rw_catalog.rw_columns WHERE name='c' ...)\n-- or query generated column definitions referencing 'c' before DROP COLUMN","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Query rw_catalog for generated column definitions before dropping columns","Drop dependent generated columns first","Keep migrations aware of computed column dependencies"],"tags":["frontend","ddl","generated-column"],"backgroundTag":"conflicting-config-options","analyzedSha":"6469eb736d691e8e9b8a419a57edd6429ca77417","analyzedAt":"2026-09-11T21:06:21.487Z","contentChangedAt":"2026-09-11T21:06:21.487Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}