Re: Disallow USING clause when altering type of generated column

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: Peter Eisentraut <peter(at)eisentraut(dot)org>
Cc: Yugo Nagata <nagata(at)sraoss(dot)co(dot)jp>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Disallow USING clause when altering type of generated column
Date: 2024-08-22 03:38:49
Message-ID: CACJufxHkv109tQtHt7EtKprWhvVkxtR7-cEBwGzcTovtVTw9_Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Aug 21, 2024 at 4:57 PM Peter Eisentraut <peter(at)eisentraut(dot)org> wrote:
>

+ /*
+ * Cannot specify USING when altering type of a generated column, because
+ * that would violate the generation expression.
+ */
+ if (attTup->attgenerated && def->cooked_default)
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_TABLE_DEFINITION),
+ errmsg("cannot specify USING when altering type of generated column"),
+ errdetail("Column \"%s\" is a generated column.", colName)));
+

errcode should be ERRCODE_FEATURE_NOT_SUPPORTED?

also
CREATE TABLE gtest27 (
a int,
b text collate "C",
x text GENERATED ALWAYS AS ( b || '_2') STORED
);

ALTER TABLE gtest27 ALTER COLUMN x TYPE int;
ERROR: column "x" cannot be cast automatically to type integer
HINT: You might need to specify "USING x::integer".

should we do something for the errhint, since this specific errhint is wrong?

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Langote 2024-08-22 03:44:33 Re: pgsql: Add more SQL/JSON constructor functions
Previous Message shveta malik 2024-08-22 03:25:24 Re: Conflict detection and logging in logical replication