risingwavelabs/risingwave · error

failed to drop column "{}" because it's referenced by a gene

Error message

failed to drop column "{}" because it's referenced by a generated column "{}"

What it means

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.

Source

Thrown at src/frontend/src/handler/alter_table_column.rs:234

        AlterTableOperation::DropColumn {
            column_name,
            if_exists,
            cascade,
        } => {
            if cascade {
                bail_not_implemented!(issue = 6903, "drop column cascade");
            }

            // Check if the column to drop is referenced by any generated columns.
            for column in original_catalog.columns() {
                if let Some(expr) = column.generated_expr() {
                    let expr = ExprImpl::from_expr_proto(expr)?;
                    let refs = expr.collect_input_refs(original_catalog.columns().len());
                    for idx in refs.ones() {
                        let refed_column = &original_catalog.columns()[idx];
                        if refed_column.name() == column_name.real_value() {
                            bail!(format!(
                                "failed to drop column \"{}\" because it's referenced by a generated column \"{}\"",
                                column_name,
                                column.name()
                            ))
                        }
                    }
                }
            }

            // Locate the column by name and remove it.
            let column_name = column_name.real_value();
            let removed_column = columns
                .extract_if(.., |c| c.name.real_value() == column_name)
                .at_most_one()
                .ok()
                .unwrap();

            if removed_column.is_some() {

View on GitHub (pinned to 6469eb736d)

Solutions

  1. Drop the dependent generated column first, then drop the target column
  2. Redefine the generated column so it no longer references the column, then drop
  3. Keep the column if the generated column is still needed

Example fix

-- before
ALTER TABLE t DROP COLUMN price; -- referenced by generated col total = price*qty
-- after
ALTER TABLE t DROP COLUMN total;
ALTER TABLE t DROP COLUMN price;
Defensive patterns

Strategy: validation

Validate before calling

SELECT dependent_column FROM rw_catalog.rw_columns
WHERE relation_id = (SELECT id FROM rw_catalog.rw_columns WHERE name='c' ...)
-- or query generated column definitions referencing 'c' before DROP COLUMN

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Understand the failure class

Background: Conflicting config options: "cannot be used together" — configuration validation errors across open-source libraries — this error's family across 162 libraries.

Related errors


AI-assisted analysis of risingwavelabs/risingwave@6469eb736d (2026-09-11). Data as JSON: /api/errors/22e57369aace1b2c. Report an issue: GitHub.