coresql / sql-query-identifier

A SQL query identifier (e.g. INSERT, SELECT, CREATE TABLE, and etc.)
https://sqlectron.github.io/sql-query-identifier/
MIT License
33 stars 10 forks source link

Fix parsing bigquery control structures #61

Closed MasterOdin closed 2 years ago

MasterOdin commented 2 years ago

PR improves parsing BigQuery control structures so that they're fully detected as their own potential standalone statements. Unlike Oracle, BigQuery's procedural language can be used without first using DECLARE or SET or BEGIN and can be completely standalone, and so we need to be able to detect that these are separate statements, and not part of a larger ANON_BLOCK like Oracle. BEGIN though for BigQuery can start an anon_block if it's the first word, and not followed by "TRANSACTION" which gives similar behavior as Oracle for that.

See CASE or FOR in the below examples as statements that are completely standalone. The other loop structures probably expect a DECLARE or SET before it, but there's no guarantee.