Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uwW6J-003ezr-E2 for pgsql-hackers@arkaria.postgresql.org; Thu, 11 Sep 2025 01:27:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1uwW6G-004T2X-9e for pgsql-hackers@arkaria.postgresql.org; Thu, 11 Sep 2025 01:27:48 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uwW6G-004T2O-10 for pgsql-hackers@lists.postgresql.org; Thu, 11 Sep 2025 01:27:48 +0000 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uwW6B-0006Xz-1r for pgsql-hackers@postgresql.org; Thu, 11 Sep 2025 01:27:47 +0000 Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-77459bc5d18so145525b3a.2 for ; Wed, 10 Sep 2025 18:27:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1757554062; x=1758158862; darn=postgresql.org; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:from:to:cc:subject:date:message-id:reply-to; bh=24Yo7FiVNO1D/XED5P6+czVw5oqPAzWkd3J4PQ9qF4k=; b=hWuXvNQBXogr1FNPd9Zi73EX4q7+O5r/pVNx8ul/rh/0bmTJLACA3qpnphtURABiGB Q7NFHN3ChouESui9OJ94L3T7ghgzjEBEXhpCVtMYB6yXZUvSZwlAXa/vT7fw6WsjNFVw JM17/fPQSB2pBFt3iY3jLocs7kvQcej9Ym4iQDbOHhM5wxvezUESH+PQ8L7KpY/z5zOY fvHvMOPqsgc9uNmYUCNFgOgqOu5F/6vFeDhDjqpAHmIoOdLodX7MK74895xvyaUUvwyF W90vicTlo8rSwE3mGV6O9lgf5jaccgZlhTiB0ZT2XdlTdpX7XdJqImNSzoi4Zd11eSKT p80g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757554062; x=1758158862; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=24Yo7FiVNO1D/XED5P6+czVw5oqPAzWkd3J4PQ9qF4k=; b=jFwyhCwwM2AxREPEJfpqO3LtnUnAZ7FIiAbYzfOZ1X0ytakoENeiGkCNGUY+vPYPrR Rw6oYbo6IGsz0fcx3+7uOc8R17HNrM8AurvnzE+GimS6UivqsSsrc6LkygCqIeKPhBoX tknr1B8NJnOfkt7q+37xsztXZEwM1RZFS06OJj3AN8nV8HVjrxxmyJwP3jJ+024JLBUG d2V9TooHsdzFZar97LVVmO/CSMBh0HQl5m0V52qZUD44VDonZCgb1s00ZLjeWep3ZHrp Isaj2zdND16E3qV6bGfb3Zlo3eTE4wUwrufn9pmGoQ75N14uD8p0xEKdwKyyfBOmsFiD 4YuQ== X-Gm-Message-State: AOJu0Yw6V1M9MDXAGq/CnbI7goaG+xSFgYn9+MPJgDj37e5H43gQPfVu QEAg68tDl/Y1mdbcpXFTlpIhr+VIASKw1/RsREGfsmU+9OyUHWz3oxV5 X-Gm-Gg: ASbGncsW8O+hvHfdU81dgUsKfLGyqfVACtmhcCFjSA2G3FVC/k6z5FceHD/1scBNeTZ jBeqfbS74CiFUdNIYgmQHOhcN/SUfmZpr+d/zI7+qOATFU6EkaRDZiNtbaL3syoonQHdScpG10H DDgiIPqyXs+mvkjx/0PHTvlBL9HnvEiA62enLPxd9ZSDOeLkE6ZSA2TYebHyrA7HT9NlksIBpuD LK1p9UUuRQ+F7K2BFf4RElohpopDuEZI48421tW+N6G423jI53dozMmHYMimRX+/64YPCvCVaUa 5xDd8tD8Be/HB0UMtK7YTLSjGc/clGXGr8Vi3GrPZb564yRQili72YWRai2VL/BWfxQo5ZIwnA+ cCk/spW9unemleeA/3E/EsVmBDXrK2lf8 X-Google-Smtp-Source: AGHT+IEfYGmQnE8XkTpGss3VnD30nx4qfJD43spds7cGZ1Vf25zL2ZFQC3P2fd3OxUkMYyFRvCocPQ== X-Received: by 2002:a05:6a00:92a5:b0:772:823b:78b5 with SMTP id d2e1a72fcca58-7742dcccbc7mr23208730b3a.8.1757554062565; Wed, 10 Sep 2025 18:27:42 -0700 (PDT) Received: from smtpclient.apple ([142.171.105.12]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-77607b1917dsm166206b3a.52.2025.09.10.18.27.40 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Sep 2025 18:27:42 -0700 (PDT) From: Chao Li Message-Id: <2B70C6CA-606B-438C-8EF2-84DCBA1C0813@gmail.com> Content-Type: multipart/alternative; boundary="Apple-Mail=_47783623-44BC-44C3-B8DD-46CB34E7C027" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.700.81\)) Subject: Re: let ALTER TABLE DROP COLUMN drop whole-row referenced object Date: Thu, 11 Sep 2025 09:27:27 +0800 In-Reply-To: Cc: PostgreSQL-development To: jian he References: X-Mailer: Apple Mail (2.3826.700.81) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Apple-Mail=_47783623-44BC-44C3-B8DD-46CB34E7C027 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Sep 9, 2025, at 11:12, jian he wrote: >=20 > hi. > I found a new way to solve this problem. >=20 > CREATE TABLE ts (a int, c int, b int > constraint cc check((ts =3D ROW(1,1,1))), > constraint cc1 check((ts.a =3D 1))); >=20 >=20 > ALTER TABLE ts DROP COLUMN a CASCADE; > will drop above all indexes, constraints and policies on the table ts. > = I agree we should delete those constraints and indices on the whole row, = otherwise, with cc (ts=3DROW(1,1,1)), once a column is dropped, it = won=E2=80=99t be able to insert data anymore: ``` evantest=3D# insert into ts values (2, 3); ERROR: new row for relation "ts" violates check constraint "cc" DETAIL: Failing row contains (2, 3). evantest=3D# insert into ts values (1, 1); ERROR: cannot compare record types with different numbers of columns ``` But v2 needs a rebase, I cannot apply it to master. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/ --Apple-Mail=_47783623-44BC-44C3-B8DD-46CB34E7C027 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8

On Sep 9, 2025, at 11:12, jian he = <jian.universality@gmail.com> wrote:

hi.
I found a new way = to solve this problem.

CREATE TABLE ts (a int, c int, b int
=    constraint cc check((ts =3D ROW(1,1,1))),
=    constraint cc1 check((ts.a =3D 1)));


ALTER = TABLE ts DROP COLUMN a CASCADE;
will drop above all indexes, = constraints and policies on the table ts.
<v2-0001-ALTER-TABLE-DROP-COLUMN-drop-wholerow-r= eferenced-object.patch>

<= /div>
I agree we should delete those constraints and indices on the = whole row, otherwise, with cc (ts=3DROW(1,1,1)), once a column is = dropped, it won=E2=80=99t be able to insert data = anymore:

```
evantest=3D# insert = into ts values (2, 3);
ERROR:  new row for relation "ts" = violates check constraint "cc"
DETAIL:  Failing row = contains (2, 3).
evantest=3D# insert into ts values (1, = 1);
ERROR:  cannot compare record types with different = numbers of columns
```

But v2 = needs a rebase, I cannot apply it to master.

Best = regards,
--
Chao Li (Evan)
HighGo Software = Co., Ltd.
https://www.highgo.com/




= --Apple-Mail=_47783623-44BC-44C3-B8DD-46CB34E7C027--