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 1xGyOJ-00000002kLi-2BGk for pgsql-bugs@arkaria.postgresql.org; Wed, 14 Oct 2026 12:47:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xGyOI-000000038gD-2HrQ for pgsql-bugs@arkaria.postgresql.org; Wed, 14 Oct 2026 12:47:30 +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 1xGgFQ-0000000FTvi-2gQf for pgsql-bugs@lists.postgresql.org; Tue, 13 Oct 2026 17:25: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 1xGgFO-00000001uUD-0m2H for pgsql-bugs@lists.postgresql.org; Tue, 13 Oct 2026 17:25: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=dVJbldl9+jFF9rqlyOq8nO42OhA5eI+qKV9C/+rIsrU=; b=sR6KqxkwRJXialk9UWogoVPCBR FRDGw0lMeVdviVB902ZTORgQI12pSowrbuxO6SYc1z9qRzVie+I5zJoc1An7v2yr9EiS7FtjU5da5 zRpcqC1hWP67TWBkeHj2QnJZba1C019CjXf1f+A+fKjHuKwZ/+nj+fS7iRozIRr6R7j+E+Seag+I8 e0wXVgoaC7g110f8F2HgLnTT9LtF5c5GJW3qGDk74sfWvpqQNRo0okdbU3z+1F5NXo3hLsNfTEzrz 4u+h9doghFS7WRow1ErjaNAiDAROLjQf5jIAyWRngkLnSMqZbi0aB5ihbJV01p1gUwxL3j7mG1Ex6 YO3Wr7yw==; 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 1xGgFM-00000005PRQ-3fAy for pgsql-bugs@lists.postgresql.org; Tue, 13 Oct 2026 17:25: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 1xGgFL-0000000GtYA-1kKi for pgsql-bugs@lists.postgresql.org; Tue, 13 Oct 2026 17:25:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19756: ALTER COLUMN TYPE USING gives wrong values on partitions with IS NULL To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: zj4204@gmail.com Reply-To: zj4204@gmail.com, pgsql-bugs@lists.postgresql.org Date: Tue, 13 Oct 2026 17:24:13 +0000 Message-ID: <19756-046a8a872ba33d27@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: 19756 Logged by: kalakala Email address: zj4204@gmail.com PostgreSQL version: 18.6 Operating system: Debian 13 (official Docker image postgres:18.6) Description: =20 ALTER TABLE ... ALTER COLUMN ... TYPE ... USING stores wrong values in partitions and inheritance children whose column numbers differ from the parent's (here the parent has a dropped column). This happens when the USING expression contains IS [NOT] NULL, IS [NOT] TRUE/FALSE/UNKNOWN, or a named function argument. CREATE TABLE pu (x int, k int, a int, b int, c int) PARTITION BY LIST (k); ALTER TABLE pu DROP COLUMN x; CREATE TABLE pu1 PARTITION OF pu FOR VALUES IN (1); INSERT INTO pu VALUES (1, 5, NULL, 9); ALTER TABLE pu ALTER COLUMN a TYPE bigint USING CASE WHEN b IS NULL THEN -1 ELSE a END; SELECT k, a, b, c FROM pu; k | a | b | c ---+---+---+--- 1 | 5 | | 9 Expected a =3D -1, because b is NULL. The same statements on a table without partitions give a =3D -1, and so does 12.22. With num_nulls(b) =3D 1 in pla= ce of b IS NULL, the result is also -1. b IS UNKNOWN and b IS NOT TRUE (with boolean b and c) give the same wrong result. With a named argument on the same layout, USING extract(day from make_interval(days =3D> b))::int on a row with b =3D 2, c =3D 30 sets a =3D= 30. The positional form make_interval(0, 0, 0, b) sets a =3D 2. Two variants fail with an internal error instead: CREATE TABLE r (a int); CREATE TABLE r1 () INHERITS (r); ALTER TABLE r ALTER COLUMN a TYPE int USING (1 IS NULL)::int; ERROR: XX000: unrecognized node type: 7 LOCATION: transformExprRecurse, parse_expr.c:376 CREATE TABLE p1 (x int, a int, b int); ALTER TABLE p1 DROP COLUMN x; CREATE TABLE c1 () INHERITS (p1); INSERT INTO c1 VALUES (30, NULL); ALTER TABLE p1 ALTER COLUMN a TYPE int USING (b IS NULL)::int; ERROR: XX000: attribute number 3 exceeds number of columns 2 LOCATION: CheckVarSlotCompatibility, execExprInterp.c:2411 The first of these fails although r1 has the same column layout as r. Reproduced on 18.6, 19beta4 and 13.23 (PGDG Debian packages in the official Docker images). 12.22 gives the expected result in every case above.