disallow ALTER VIEW SET DEFAULT when the corresponding base relation column is a generated column - Mailing list pgsql-hackers

From jian he
Subject disallow ALTER VIEW SET DEFAULT when the corresponding base relation column is a generated column
Date
Msg-id CACJufxHvxKd8yaV_VD-Exb0YAXtGJc_u3zrptBabi8_fUipcjA@mail.gmail.com
Whole thread Raw
Responses Re: disallow ALTER VIEW SET DEFAULT when the corresponding base relation column is a generated column
List pgsql-hackers
hi.

CREATE TABLE gtest1 (a int, b int GENERATED ALWAYS AS (a * 2) STORED);
CREATE VIEW gtest1v AS SELECT * FROM gtest1;
ALTER VIEW gtest1v ALTER COLUMN b SET DEFAULT 100;

INSERT INTO gtest1v VALUES (8, DEFAULT) returning *;
ERROR:  cannot insert a non-DEFAULT value into column "b"
DETAIL:  Column "b" is a generated column.

we can make
ALTER VIEW gtest1v ALTER COLUMN b SET DEFAULT 100;
error out,
then
INSERT INTO gtest1v VALUES (8, DEFAULT) returning *;
will work just fine.

obviously,
INSERT INTO gtest1v VALUES (8, 1) returning *;
will fail.


we can do this by in ATExecColumnDefault,
checking if
* gtest1v is updatable view or not
* column b is an updatable column or not
* column b on view corresponding base relation's column is a generated
column or not.

if all these conditions meet then, we error out saying
``cannot alter column \"%s\" on updateable view ``.


what do you think?

Attachment

pgsql-hackers by date:

Previous
From: Nisha Moond
Date:
Subject: Re: Fix slot synchronization with two_phase decoding enabled
Next
From: "Hayato Kuroda (Fujitsu)"
Date:
Subject: Regression test fails when 1) old PG is installed and 2) meson/ninja build is used