-
-
Notifications
You must be signed in to change notification settings - Fork 540
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
Syntax Error Occurs When Using AS Clause with ON DUPLICATE KEY UPDATE #7638
Comments
This SQL syntax extension will get better visibility in the Dolt repo, so I'm going to move it over there. |
Hi Noguchi! Unfortunately, it looks like we don't currently support the "row alias" syntax for insert statements. As a workaround, we do support the previous syntax (using the VALUES function), so your example in the previous syntax would look like this:
I agree that supporting newer MySQL syntax is valuable. This doesn't seem like a difficult add either: we already support referencing subquery aliases in update statements, which can be demonstrated with the following equivalent statement:
So adding support for this should be straightforward. I can do it today. |
I've been digging into this a bit more. The Unfortunately, there are some quirks that make this less straightforward:
|
Update: I actually misunderstood how the column aliases work in this case. From the docs:
|
This is an issue for us as well. We recently updated our query builders to use the new alias syntax instead of the old The fact that it's now supported by the parser also makes the resulting error message a bit confusing, since the following: INSERT INTO tbl (id, name) VALUES (1, 'test1'), (2, 'test2'), (3, 'test3') AS tbl_new
ON DUPLICATE KEY UPDATE tbl.name = tbl_new.name; results in a |
I apologize for the confusing error message: when we added support to the parser, we added a new error message that was supposed to be more clear:
If you're not seeing that error message, that's a bug. Last time, we held off on implementing this because the name resolution rules were deceptively tricky, and we could point people to the old syntax as a workaround. But given that the old syntax is deprecated and people are migrating, we need to be able to handle the new synatx. I'm going to take another stab at it today. |
Update: I have a draft PR that gets the simplest case working (row alias, no column alias): dolthub/go-mysql-server#2534 So with this PR, both @arvidfm and @koh789's sample queries should work. I haven't fully tested it, and it does have some caveats:
I'm currently working on both of these issues. |
@nicktobey If it helps, that name resolution behaviour doesn't actually seem to be the case in MySQL, or at least not with Percona Server 8.3. I get an error message complaining that the column name is ambiguous if I do either |
@arvidfm You're absolutely right! I was mistaken. I got column aliases working last night too. I'm adding tests and will make the final PR shortly. |
PR is ready. It took some finesse to make it work properly with out-of-order insert statements, but everything should be working now. |
@nicktobey I noticed the related PR is merged while this issue is still open, is there any further work required for this or is it ready to be used? |
This is in 1.39.5: https://github.com/dolthub/dolt/releases/tag/v1.39.5 |
Perfect, thank you for the confirmation! |
Sorry for the late reply. |
Using version: v0.18.0
When executing the following query, an error (
syntax error at position 134 near 'AS') occurs.
)What could be the cause of this?
https://dev.mysql.com/doc/refman/8.0/en/insert-on-duplicate.html
If possible, I would be grateful if you could support version 8.0.20 and later.
Thank you for your consideration.
The text was updated successfully, but these errors were encountered: