-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot combine DELETE .. USING .. ORDER BY .. LIMIT #123565
Comments
Hello, I am Blathers. I am here to help you get the issue triaged. Hoot - a bug! Though bugs are the bane of my existence, rest assured the wretched thing will get the best of care here. I was unable to automatically find someone to ping. If we have not gotten back to your issue within a few business days, you can try the following:
🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf. |
I've reverse engineered this and this seems to work: delete from t
using u
where t.i = u.i
order by t.rowid, t.i
limit 1; But this risks to implement a different semantics, I think? |
Also, the problem doesn't appear with explicit primary keys. This works: create table t (i int primary key);
create table u (i int primary key);
delete from t
using u
where t.i = u.i
order by t.i
limit 1; |
Thank you for filing the issue, @lukaseder.
Yes, this has different semantics. This would delete the row with the lowest rowid rather than the row with the lowest i. I think a rewrite like this could be a workaround: DELETE FROM t WHERE t.rowid IN (
SELECT t.rowid FROM t JOIN u ON t.i = u.i ORDER BY t.i LIMIT 1
); |
Closing as a dupe of #89817. |
Describe the problem
I tried running a
DELETE .. USING .. ORDER BY .. LIMIT
query but it resulted in an error that seems to hint at an internal transformation flaw for the syntax combination:To Reproduce
Remove the
ORDER BY
clause, and the problem goes awayExpected behavior
The query should run normally.
If applicable, add screenshots to help explain your problem.
Environment:
Jira issue: CRDB-38401
The text was updated successfully, but these errors were encountered: