Fix ALTER TABLE DROP EXPRESSION with inheritance hierarchy

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Fix ALTER TABLE DROP EXPRESSION with inheritance hierarchy
Date: 2025-08-24 09:05:01
Message-ID: CACJufxEW9L279n=fpUg+qrXYP6g4oh_RLOTHVVphkWDVqaNGDw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

hi.

--this ALTER COLUMN DROP EXPRESSION work as expected
DROP TABLE IF EXISTS parent cascade;
CREATE TABLE parent (a int, d INT GENERATED ALWAYS AS (11) STORED);
CREATE TABLE child () INHERITS (parent);
ALTER TABLE parent ALTER COLUMN d DROP EXPRESSION;

----- the below (ALTER COLUMN DROP EXPRESSION) should also work.
-----
DROP TABLE IF EXISTS parent cascade;
CREATE TABLE parent (a int, d INT GENERATED ALWAYS AS (11) STORED);
CREATE TABLE child () INHERITS (parent);
CREATE TABLE grandchild () INHERITS (child);
ALTER TABLE parent ALTER COLUMN d DROP EXPRESSION;

but currently it will generated error:
ERROR: 0A000: ALTER TABLE / DROP EXPRESSION must be applied to child tables too
LOCATION: ATPrepDropExpression, tablecmds.c:8734

The attached patch fixes this potential issue.

Attachment Content-Type Size
v1-0001-Fix-ALTER-TABLE-DROP-EXPRESSION-with-inheritance-hierarch.patch text/x-patch 7.6 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Srinath Reddy Sadipiralla 2025-08-24 12:28:44 Re: Potential problem in commit f777d773878 and 4f7f7b03758
Previous Message Noah Misch 2025-08-24 01:08:11 Re: Non-text mode for pg_dumpall