In PostgreSQL 11, the following expression
UPDATE test_table SET ("column_a","column_b") = ('value-a','value-b') WHERE "column_a" = 'value-c'
is accepted and performs the update.
But for a single column / value, like
UPDATE test_table SET ("column_a") = ('value-a') WHERE "column_a" = 'value-c'
it gives an error. ROW
must be supplied, like
UPDATE test_table SET ("column_a") = ROW ('value-a') WHERE "column_a" = 'value-c'
Is there an explanation why this behavior was chosen? Is there an ambiguity if ROW
is missing?
Best Answer
As is often the case, the answer is to be found in documentation.
The
UPDATE
reference says, in particular:whereas "row constructor" is defined like so:
The last sentence kind of makes sense, because a single expression in parentheses is ambiguous by itself and can be confused with a simple parenthesised expression.
This syntax was introduced in version 10 -- HT to ypercube™.