Open rytaft opened 1 year ago
Here is the supported syntax in Postgres:
postgres=# \h UPDATE
Command: UPDATE
Description: update rows of a table
Syntax:
[ WITH [ RECURSIVE ] with_query [, ...] ]
UPDATE [ ONLY ] table_name [ * ] [ [ AS ] alias ]
SET { column_name = { expression | DEFAULT } |
( column_name [, ...] ) = [ ROW ] ( { expression | DEFAULT } [, ...] ) |
( column_name [, ...] ) = ( sub-SELECT )
} [, ...]
[ FROM from_item [, ...] ]
[ WHERE condition | WHERE CURRENT OF cursor_name ]
[ RETURNING * | output_expression [ [ AS ] output_name ] [, ...] ]
URL: https://www.postgresql.org/docs/14/sql-update.html
Describe the problem
When I execute an
UPDATE
statement with anORDER BY ... LIMIT
clause, it results in a confusing error: "ERROR: SELECT DISTINCT ON expressions must match initial ORDER BY expressions".To Reproduce
On a single-node local cluster, run:
The last statement fails with error:
This is confusing, since there is no
DISTINCT ON
expression in theUPDATE
statement (the optimizer adds one, but the user doesn't know that...).Expected behavior
The returned error should be less confusing. Postgres seems to be more restrictive, and doesn't even allow the
ORDER BY
orLIMIT
clauses in this context. Maybe we should do the same.Here is Postgres' error:
Environment:
Jira issue: CRDB-25427