cloudspannerecosystem / memefish

memefish is the foundation to analyze Spanner SQL
https://cloudspannerecosystem.dev/memefish/
MIT License
76 stars 19 forks source link

Incompatibility: Paren query expression should able to contain CTE #203

Open apstndb opened 2 days ago

apstndb commented 2 days ago

It is a valid query.

$ gcloud spanner databases execute-sql ${SPANNER_DATABASE} --sql '(WITH cte AS (SELECT 1 AS n) SELECT * FROM cte)'
n
1

but, memefish can't parse it.

$ go run ./tools/parse/main.go --mode query "(WITH cte AS (SELECT 1 AS n) SELECT * FROM cte)"                                                                                
2024/11/13 23:35:51 syntax error: :1:2: expected token: SELECT, but: WITH

  1:  (WITH cte AS (SELECT 1 AS n) SELECT * FROM cte)
       ^~~~
exit status 1

Related syntax

https://cloud.google.com/spanner/docs/reference/standard-sql/query-syntax#sql_syntax

query_statement:
  [ statement_hint_expr ]
  [ table_hint_expr ]
  [ join_hint_expr ]
  query_expr

query_expr:
  [ WITH cte[, ...] ]
  { select | ( query_expr ) | set_operation }
  [ ORDER BY expression [{ ASC | DESC }] [, ...] ]
  [ LIMIT count [ OFFSET skip_rows ] ]

Considerations