Skip to content
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

SQL statement rendering problem #403

Closed
pchemguy opened this issue Jun 13, 2024 · 5 comments · Fixed by apache/datafusion-sqlparser-rs#1317
Closed

SQL statement rendering problem #403

pchemguy opened this issue Jun 13, 2024 · 5 comments · Fixed by apache/datafusion-sqlparser-rs#1317
Labels
bug Something isn't working

Comments

@pchemguy
Copy link
Contributor

pchemguy commented Jun 13, 2024

SQL statement

INSERT INTO currencies(id, name, to_rub)
VALUES (CAST(:id AS INT), :name, CAST(:to_rub AS NUMERIC))
ON CONFLICT(id) DO
UPDATE SET (name, to_rub) = (:name, CAST(:to_rub AS NUMERIC)) WHERE id = CAST(:id AS INT)
RETURNING
    'redirect'                      AS component,
    'currency_item_r.sql?id=' || id AS link;

throws an error

Failed to execute SQL statement:
INSERT INTO currencies (id, name, to_rub) VALUES (CAST(CAST(? AS TEXT) AS INT), CAST(? AS TEXT), CAST(CAST(? AS TEXT) AS NUMERIC)) ON CONFLICT(id) DO UPDATE SET name.to_rub = (CAST(? AS TEXT), CAST(CAST(? AS TEXT) AS NUMERIC)) WHERE id = CAST(CAST(? AS TEXT) AS INT) RETURNING 'redirect' AS component, 'currency_item_r.sql?id=' || id AS link;
                                                                                                                                                                     
line 1, character 165

error returned from database: (code: 1) near ".": syntax error (at statement byte offset 165)
(code: 1) near ".": syntax error (at statement byte offset 165)

Basically, the fragment

DO UPDATE SET (name, to_rub)

is transformed to

DO UPDATE SET name.to_rub
@pchemguy pchemguy added the bug Something isn't working label Jun 13, 2024
@lovasoa
Copy link
Collaborator

lovasoa commented Jun 13, 2024

Hi ! The do is present in your original query, it doesn't seem to have been added by sqlpage. Can you provide detailed reproduction instructions ?

@lovasoa
Copy link
Collaborator

lovasoa commented Jun 13, 2024

Oh, sorry, I see, you were talking about the dot, not the DO.

Reported upstream as apache/datafusion-sqlparser-rs#1311

In the meantime, you can use the standard update syntax instead of SQLite row values.

@pchemguy
Copy link
Contributor Author

My apologies for confusing question, edited it appropriately.

@lovasoa
Copy link
Collaborator

lovasoa commented Jun 17, 2024

I made a pull request upstream, hopefully this will be fixed in the next release of sqlparser, which we can then integrate here

@lovasoa
Copy link
Collaborator

lovasoa commented Jul 10, 2024

I just updated the parser, it's fixed :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants