lovasoa / SQLpage

SQL-only webapp builder, empowering data analysts to build websites and applications quickly
https://sql.ophir.dev
MIT License
880 stars 62 forks source link

SQL statement rendering problem #403

Open pchemguy opened 2 weeks ago

pchemguy commented 2 weeks ago

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
lovasoa commented 2 weeks ago

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 commented 2 weeks ago

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

Reported upstream as https://github.com/sqlparser-rs/sqlparser-rs/issues/1311

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

pchemguy commented 2 weeks ago

My apologies for confusing question, edited it appropriately.

lovasoa commented 2 weeks ago

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