Re: Fix ALTER TABLE DROP EXPRESSION with inheritance hierarchy

Peter Eisentraut <peter@eisentraut.org>

From: Peter Eisentraut <peter@eisentraut.org>
To: Kirill Reshke <reshkekirill@gmail.com>, jian he <jian.universality@gmail.com>
Cc: PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2025-11-04T18:10:20Z
Lists: pgsql-hackers
On 25.08.25 15:04, Kirill Reshke wrote:
> So we need to detect if the user did ALTER TABLE or ALTER TABLE ONLY.
> And we have two parameters passed to ATPrepDropExpression: "recurse"
> and "recursing".
> First is about whether the user specified ONLY option and second is
> about if we are recursing in our AT code. So maybe fix it as in
> attached?

I find that tablecmds.c uses these two arguments in not entirely 
consistent ways.

I would have expected that if you write a command that is supposed to 
recurse (no ONLY) and you are some levels down into the recursing, then 
recursing=true, of course, but shouldn't recurse=true as well, to 
reflect the command that was written?

Some code works like that, for example ATExecDropColumn() and 
ATExecSetNotNull().  I probably originally adapted code from places like 
that.

But in ATPrepDropExpression(), when you're recursing, then recurse is 
always false.  That is hardcoded in the ATPrepCmd() call in 
ATSimpleRecursion().  Does that make sense?

I mean, there might be complex reasons, ALTER TABLE code is complicated, 
but I don't find this explained anywhere.

If this worked more consistently, then the DROP EXPRESSION code might 
actually work correctly as written.