multi-row INSERT broken with a sublink in a target column subscript

From: Amit Langote <amitlangote09(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: multi-row INSERT broken with a sublink in a target column subscript
Date: 2026-10-28 00:42:18
Message-ID: CA+HiwqHCZLZV_20nz3fQX+1=vyFLDMbG0_3wY=QujNKZWts0nw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

When looking at whether there exist other sites in the parser that are
like bug #19786, Claude found $subject.

CREATE TABLE ta (a int[]);
INSERT INTO ta (a[(SELECT 1)]) VALUES (1), (2);
ERROR: unexpected non-SELECT command in SubLink

The problem is that transformInsertStmt() transforms the target
columns' indirection once per VALUES row without copying it, while
transformSubLink() modifies the raw SubLink in place.

a[(1 IS NULL)::int + 1] fails too, like this:

INSERT INTO ta (a[(1 IS NULL)::int + 1]) VALUES (1), (2);
ERROR: unrecognized node type: 7

Attached patch fixes this.

--
Thanks, Amit Langote

Attachment Content-Type Size
v1-0001-Fix-multi-row-INSERT-with-a-sublink-in-a-target-c.patch application/octet-stream 3.5 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message shihao zhong 2026-10-28 01:13:42 Re: Skip prefetch for block references that follow a FPW or WILL_INIT of the same block
Previous Message shihao zhong 2026-10-28 00:41:29 Re: [PATCH] pg_upgrade: add --initdb option to create the new cluster automatically