From: | jian he <jian(dot)universality(at)gmail(dot)com> |
---|---|
To: | Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> |
Cc: | PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: let ALTER TABLE DROP COLUMN drop whole-row referenced object |
Date: | 2025-09-12 09:22:37 |
Message-ID: | CACJufxHmmsg7GTD_LpGGam09+Aq4KkYHe2dfPgtGjrUELqbK=w@mail.gmail.com |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Thu, Sep 11, 2025 at 9:27 AM Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> wrote:
>
> But v2 needs a rebase, I cannot apply it to master.
>
hi.
please check attached v3-0001, v3-0002.
v3-0001: ALTER TABLE DROP COLUMN cascade to drop any whole-row
referenced constraints and indexes.
v3-0002: ALTER COLUMN SET DATA TYPE error out when whole-row
referenced constraint exists
with the v3-0002 patch,
CREATE TABLE ts (a int, c int, b int constraint cc check((ts = ROW(1,1,1))));
ALTER TABLE ts ALTER COLUMN b SET DATA TYPE INT8;
ERROR: cannot alter table column "ts"."b" to type bigint because
constraint "cc" uses table "ts" row type
HINT: You might need to drop constraint "cc" first to change column
"ts"."b" data type
Of course, even if we do not error out, regular insert will fail too.
insert into ts values(1,1,1);
ERROR: cannot compare dissimilar column types bigint and integer at
record column 3
src7=# \errverbose
ERROR: 42804: cannot compare dissimilar column types bigint and
integer at record column 3
LOCATION: record_eq, rowtypes.c:1193
then you need debug to find out the root error cause is constraint cc
is not being satisfied;
and you still need to handle the corrupted constraint cc afterward.
With the v3-0002 patch, ALTER TABLE SET DATA TYPE provides an explicit error
message that helps quickly identify the problem.
So I guess it should be helpful.
--------------------------------
index expression/predicate and check constraint expression can not contain
subquery, that's why using pull_varattnos to test whole-row containment works
fine. but pull_varattnos can not cope with subquery, see pull_varattnos
comments.
row security policy can have subquery, for example:
CREATE POLICY p1 ON document AS PERMISSIVE
USING (dlevel <= (SELECT seclv FROM uaccount WHERE pguser = current_user));
so I am still working on whole-row referenced policies interacting with ALTER
TABLE SET DATA TYPE/ALTER TABLE DROP COLUMN.
Attachment | Content-Type | Size |
---|---|---|
v3-0002-disallow-ALTER-COLUMN-SET-DATA-TYPE-when-wholerow-referenced-cons.patch | text/x-patch | 4.5 KB |
v3-0001-ALTER-TABLE-DROP-COLUMN-drop-wholerow-referenced-object.patch | text/x-patch | 10.4 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Richard Guo | 2025-09-12 09:34:43 | Re: Eager aggregation, take 3 |
Previous Message | Shlok Kyal | 2025-09-12 09:04:26 | Re: issue with synchronized_standby_slots |