Re: ALTER TABLE ALTER CONSTRAINT misleading error message

Fujii Masao <masao.fujii@oss.nttdata.com>

From: Fujii Masao <masao.fujii@oss.nttdata.com>
To: jian he <jian.universality@gmail.com>
Cc: Álvaro Herrera <alvherre@kurilemu.de>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2025-06-27T06:11:41Z
Lists: pgsql-hackers

Attachments


On 2025/06/18 1:00, Fujii Masao wrote:
> I had overlooked that commands other than ALTER TABLE can also trigger
> this error. So mentioning just ALTER TABLE ... might be a bit misleading.
> Would it be better to use a message like
> "ALTER action ALTER CONSTRAINT ... NOT VALID is not supported",
> similar to what we already do in tablecmd.c?

I had this concern because other commands, like ALTER SEQUENCE ALTER CONSTRAINT NOT VALID,
can also hit this error, and seeing an error message that starts with ALTER TABLE ...
in that context can be confusing. That's why I thought a message like:

     ERROR: ALTER action ALTER CONSTRAINT ... NOT VALID is not supported

would be clearer.

However, most ALTER ... commands (other than ALTER TABLE) don't support ALTER CONSTRAINT
at all, not just the NOT VALID clause. So in those cases, I think we should use
the existing error handling for other commands and emit an error like:

     ERROR: ALTER action ALTER CONSTRAINT cannot be performed on relation ...

Only in the case of ALTER TABLE should we produce a more specific message, like:

     ERROR: ALTER TABLE ... ALTER CONSTRAINT ... NOT VALID is not supported

To make this distinction, I just started thinking it's better to raise the error
in ATExecAlterConstraint() rather than in gram.y. I've attached a draft patch that
follows this approach.

Regards,

-- 
Fujii Masao
NTT DATA Japan Corporation

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. Fix bogus grammar for a CREATE CONSTRAINT TRIGGER error

  2. Fix error message for ALTER CONSTRAINT ... NOT VALID