PostgreSQL 10 parenthesized single-column updates can produce errors

From: Rob McColl <rob(at)robmccoll(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: PostgreSQL 10 parenthesized single-column updates can produce errors
Date: 2017-10-31 20:27:22
Message-ID: CAOC3wJibepvOGYmyj5--Fjk1=Z8y8qD9r6jywGi+si2B4q+GtQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Between 9.6.5 and 10, the handling of parenthesized single-column UPDATE
statements changed. In 9.6.5, they were treated identically to
unparenthesized single-column UPDATES. In 10, they are treated as
multiple-column updates. This results in this being valid in Postgres
9.6.5, but an error in Postgres 10:

CREATE TABLE test (id INT PRIMARY KEY, data INT);
INSERT INTO test VALUES (1, 1);
UPDATE test SET (data) = (2) WHERE id = 1;

In 10 and the current master, this produces the error:

errmsg("source for a multiple-column UPDATE item must be a sub-SELECT or
ROW() expression")

I believe that this is not an intended change or behavior, but is instead
an unintentional side effect of 906bfcad7ba7cb3863fe0e2a7810be8e3cd84fbd
Improve handling of "UPDATE ... SET (column_list) = row_constructor". (
https://github.com/postgres/postgres/commit/906bfcad7ba7cb3863fe0e2a7810be
8e3cd84fbd).

This is a small patch to the grammar that restores the previous behavior by
adding a rule to the set_clause rule and modifying the final rule of the
set_clause rule to only match lists of more then one element. I'm not sure
if there are more elegant or preferred ways to address this.

Compiled and tested on Ubuntu 17.04 Linux 4.10.0-33-generic x86_64.

Regression test added under the update test to cover the parenthesized
single-column case.

I see no reason this would affect performance.

Thanks,
-rob

--
Rob McColl
@robmccoll
rob(at)robmccoll(dot)com
205.422.0909 <(205)%20422-0909>

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Pavel Stehule 2017-10-31 20:33:35 Re: proposal: schema variables
Previous Message Pavel Stehule 2017-10-31 20:21:22 Re: SQL procedures