sql: UPDATE ... FROM ... ORDER BY
and DELETE ... USING
returns errors when the columns in the ORDER BY
are from the table in the FROM
clause.
#89817
Labels
C-bug
Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.
T-sql-queries
SQL Queries Team
Describe the problem
In
UPDATE ... FROM ... ORDER BY ...
statements where the columns specified in theORDER BY
clause come from theFROM
table, cockroach returns an error to the user which statingerror (42P10): SELECT DISTINCT ON expressions must match initial ORDER BY expressions
. This is possibly because columns in theFROM
clause are not in scope of theORDER BY
clause of anUPDATE FROM
statement.To Reproduce
Currently, we do not test
ORDER BY
clauses inUPDATE ... FROM
statements, though we support it as shown in the docs. Adding an optbuilder test topkg/sql/opt/optbuilder/testdata/update_from
:UPDATE abc SET b = other.d FROM dec AS other WHERE abc.a = other.k ORDER BY other.k DESC LIMIT 2
returns this error:error (42P10): SELECT DISTINCT ON expressions must match initial ORDER BY expressions
Note that the tables used in this test are already present in the optbuilder test file, and are:
Expected behavior
UPDATE ... FROM should allow a user to
ORDER BY
by the contents of theFROM
table.Jira issue: CRDB-20455
The text was updated successfully, but these errors were encountered: