Skip to content

Dropping column not allowed because it is referenced in a materialized view, which isn't true (although a CTE with the same column name exists) #78060

@nielsreijers

Description

@nielsreijers

Company or project name

No response

Describe what's wrong

I'm trying to drop a column val from a source table that has an MV attached.
The MV uses a CTE that selects a constant value as val, but doesn't read the val in the source table.

I think this should allow me to drop val from the source table, but this results in a Trying to ALTER DROP column val which is referenced by materialized view ['dest_mv'] error.

Without the CTE it works correctly.

I know the example looks quite pointless. The actual case where I encountered this behaviour is in the down script for a migration that added the val column to the source table, while the previous version of the code was using now() as a default.

Does it reproduce on the most recent release?

Yes

How to reproduce

See fiddle

Expected behavior

The val column should be dropped since the MV doesn't use it.

Error message and/or stacktrace

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    potential bugTo be reviewed by developers and confirmed/rejected.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions