risingwavelabs / risingwave

Best-in-class stream processing, analytics, and management. Perform continuous analytics, or build event-driven applications, real-time ETL pipelines, and feature stores in minutes. Unified streaming and batch. PostgreSQL compatible.
https://go.risingwave.com/slack
Apache License 2.0
7.03k stars 578 forks source link

sqlparser: confusing error message (keyword used as identifier) #17458

Open xxchan opened 4 months ago

xxchan commented 4 months ago
WITH arr AS (SELECT header_col_combined FROM additional_columns),
WITH unnested AS (SELECT unnest(header_col_combined) FROM arr)
select * from unnested group by 1;

ERROR:  Failed to run the query

Caused by:
  sql parser error: expected AS, found: unnested
LINE 2: WITH unnested AS (SELECT unnest(header_col_combined) FROM arr)
             ^

should be: unexpected WITH

github-actions[bot] commented 2 months ago

This issue has been open for 60 days with no activity.

If you think it is still relevant today, and needs to be done in the near future, you can comment to update the status, or just manually remove the no-issue-activity label.

You can also confidently close this issue as not planned to keep our backlog clean. Don't worry if you think the issue is still valuable to continue in the future. It's searchable and can be reopened when it's time. 😄

chagelo commented 1 month ago

create table with; is ok, but here with arr_a as (select * from table_name), with as (select * from table_name) select * from with;, the second with should be identified as a keyword?

In addition, there are some other errors.

select *, select * from a;
ERROR:  Failed to run the query

Caused by:
  sql parser error: syntax error at or near from at line 1, column 20
LINE 1: select *, select * from a;
                                ^
select *, from from a;
ERROR:  Failed to run the query

Caused by:
  sql parser error: syntax error at or near from at line 1, column 11
LINE 1: select *, from from a;
                       ^

I think they are caused by that we don't correctly resolve the tokens followed by comma.

chagelo commented 4 weeks ago

@xxchan I mean, create table with is OK(table name), here with is keyword but identified as a identifier, but you say that should be: unexpected WITH, it means with should not be identified as a identifier(column name), it's not reasonable. So I think the error message is fine.

xxchan commented 4 weeks ago

create table with is OK(table name), here with is keyword but identified as a identifier

What do you mean by: it's ok to use with as an idendifier?

e.g., in postgres, this will fail:

xxchan@/tmp:postgres> create table with(x int);
syntax error at or near "with"
LINE 1: create table with(x int)

(Also note that create table "with"(x int); is OK.)

If you mean this is the current behavior of RisingWave, I think we can definitely change that.

chagelo commented 4 weeks ago

Oh, I got you, thanks.