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

bug(sqlparser): properly handle ambiguity in INSERT INTO table_name (SELECT ...) #19875

Open
cloudcarver opened this issue Dec 20, 2024 · 2 comments
Labels
component/frontend Protocol, parsing, binder. priority/low

Comments

@cloudcarver
Copy link
Contributor

Version:

PostgreSQL 13.14.0-RisingWave-2.1.0 (unknown)

Steps to reproduce:

CREATE TABLE src2 (a INT, b INT);
CREATE TABLE dst2 (c INT, d INT);
INSERT INTO dst2 (SELECT * FROM src2);

Postgres supports this syntax. So RisingWave might also need to adapt it.

@github-actions github-actions bot added this to the release-2.2 milestone Dec 20, 2024
@xiangjinwu xiangjinwu changed the title failed to run INSERT INTO table_name (SELECT ...) fix(sqlparser): properly handle ambiguity in INSERT INTO table_name (SELECT ...) Dec 20, 2024
@xiangjinwu xiangjinwu changed the title fix(sqlparser): properly handle ambiguity in INSERT INTO table_name (SELECT ...) bug(sqlparser): properly handle ambiguity in INSERT INTO table_name (SELECT ...) Dec 20, 2024
@xiangjinwu
Copy link
Contributor

xiangjinwu commented Dec 20, 2024

Note that RisingWave already support it without parentheses:

INSERT INTO dst2 SELECT * FROM src2;

The problem of parentheses is the ambiguity between the follow two SQLs:

INSERT INTO dst2 (d) SELECT 1;
INSERT INTO dst2 (SELECT * FROM src2);

Right now it seems our sqlparser always tries to parse a column list inside parentheses and would report an error immediately without backtracking and trying the other possibility: parsing a parentheses Query.

Is avoiding the unnecessary parentheses an option in your use case? The sqlparser may (or may not, I have not checked this specific case) need a moderate refactor to support backtracking well.

Of course another workaround also works:

INSERT INTO dst2(c, d) (SELECT * FROM src2);

@xiangjinwu xiangjinwu added the component/frontend Protocol, parsing, binder. label Dec 20, 2024
@cloudcarver
Copy link
Contributor Author

Is avoiding the unnecessary parentheses an option in your use case?

All good. These workarounds can work. It is just a bit confusing.

@xiangjinwu xiangjinwu removed this from the release-2.2 milestone Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/frontend Protocol, parsing, binder. priority/low
Projects
None yet
Development

No branches or pull requests

2 participants