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.98.2) (envelope-from ) id 1xKANm-00000000gwW-3VcQ for pgsql-bugs@arkaria.postgresql.org; Fri, 23 Oct 2026 08:12:11 +0000 Received: from localhost ([127.0.0.1]:35978 helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xKANm-0000000F6ms-0wFC for pgsql-bugs@arkaria.postgresql.org; Fri, 23 Oct 2026 08:12:10 +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.98.2) (envelope-from ) id 1xJtSi-0000000C9Mv-3wFa for pgsql-bugs@lists.postgresql.org; Thu, 22 Oct 2026 14:08:08 +0000 Received: from mahout.postgresql.org ([2001:4800:3e1:1::227]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xJtSg-00000000QM3-2qoZ for pgsql-bugs@lists.postgresql.org; Thu, 22 Oct 2026 14:08:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Message-ID:Date:Reply-To:Cc:From:To:Subject: Content-Transfer-Encoding:MIME-Version:Content-Type:Sender:Content-ID: Content-Description:In-Reply-To:References; bh=SpaCzApdeJ2g+Lwz6H3YDhWhlYkLVq06Oml6Z/ORAfI=; b=1DGIyu2POZTaT85MVbmbCi//Aw JSSb4lWHj/qhjts2w2sC8CCPwgmOFrOL46wBd8U4K1iVJbQp8OnDCfcaShLEJ3gYOoNeYEaqDyHPr EIj4OM+Xtc3oIfJPn3wKHgUtp4y4NqbiF9qbwEqjKo4RTXXkn8wgQkHzAXq/a2Tp6HqSHMVlEHDz/ KhIO6sLJhdzNlBGWKZYtjoGFBDlm0U4J0bVq9DbB9kuU3fCmG4RxFhmyXegFCDYjcg7uTUtMRSRpv enWm1/41mNmWUYW6DKn/BidCwA+zo7JgyjlbXhh+yOwF7ncu1LCFUOf46FCCPuItucSRlYdcKSEAm 1gkfMX4Q==; Received: from wrigleys.postgresql.org ([2a02:16a8:dc51::60]) by mahout.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xJtSe-000000016G7-3KGy for pgsql-bugs@lists.postgresql.org; Thu, 22 Oct 2026 14:08:04 +0000 Received: from localhost ([127.0.0.1] helo=wrigleys.postgresql.org) by wrigleys.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xJtSd-000000035IX-3B3z for pgsql-bugs@lists.postgresql.org; Thu, 22 Oct 2026 14:08:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19791: ALTER COLUMN TYPE fails on an INCLUDE column of an index used by a foreign key To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: alpkeles99@gmail.com Reply-To: alpkeles99@gmail.com, pgsql-bugs@lists.postgresql.org Date: Thu, 22 Oct 2026 14:07:10 +0000 Message-ID: <19791-ebe77f384f92b31b@postgresql.org> X-Auto-Response-Suppress: All Auto-Submitted: auto-generated List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk The following bug has been logged on the website: Bug reference: 19791 Logged by: Alperen Keles Email address: alpkeles99@gmail.com PostgreSQL version: 18.6 Operating system: macOS 26.7 arm64 Description: =20 Hello, Changing the type of a non-key (INCLUDE) column of a unique index fails when a foreign key references the key columns of that index: CREATE TABLE p (a int4, b int4); CREATE UNIQUE INDEX p_u ON p (a) INCLUDE (b); CREATE TABLE c (a int4 REFERENCES p (a)); ALTER TABLE p ALTER COLUMN b TYPE int8; ERROR: cannot drop index p_u because other objects depend on it DETAIL: constraint c_a_fkey on table c depends on index p_u HINT: Use DROP ... CASCADE to drop the dependent objects too. The same happens with UNIQUE (a) INCLUDE (b) and PRIMARY KEY (a) INCLUDE (b) constraints ("cannot drop constraint ..."), with a partitioned referenced table, with a self-referencing foreign key, with ALTER COLUMN b SET EXPRESSION on a stored generated column, and with changes that need no rewrite, such as varchar(5) -> varchar(10) or only a new COLLATE on b. It works without the foreign key (the index is rebuilt), when the key column a is altered instead (index and foreign key are rebuilt), and when both are altered in one statement: ALTER TABLE p ALTER COLUMN a TYPE int8, ALTER COLUMN b TYPE int8; ALTER TABLE The ALTER TABLE documentation says indexes and simple table constraints involving the column are converted automatically. As far as I can tell, RememberAllDependentForRebuilding() collects only the direct pg_depend dependents of the altered column. The index depends on a and b, but the foreign key depends only on p.a and on the index, so it is not collected when b is altered. ATPostAlterTypeCleanup() then drops the index with DROP_RESTRICT ("nothing else should be depending on these objects"), and the foreign key's dependency on the index makes that fail. Before INCLUDE, a foreign key could only depend on an index whose columns were all referenced by it. Reproduced on 18.6 (REL_18_STABLE a85b5523e67), master 158b6d5109f and 11.22, macOS arm64. Found with a query fuzzer. Regards, Alperen Keles