I think the most important characteristic of "parse-unparse" is that it never changes the semantics of the query, but "parse-unparse" can break the semantics of the query.
(*ast.Ident).SQL() quote identifiers when the identifier is the keyword using QuoteSQLIdent.
$ go run ./tools/parse --mode query 'SELECT 1 AS `SELECT`'
...
--- SQL
SELECT 1 AS `SELECT`
There are bad cases.
$ go run ./tools/parse --mode query 'SELECT 1 AS `IF`'
...
--- SQL
SELECT 1 AS IF
It is not a valid query.
spanner> SELECT 1 AS IF;
ERROR: spanner: code = "InvalidArgument", desc = "Syntax error: Unexpected keyword IF [at 1:13]\\nSELECT 1 AS IF\\n ^"
It seems that the current diff is GRAPH_TABLE and IF.
--- keywords-in-go.txt 2024-09-28 00:12:47
+++ keywords.txt 2024-09-28 00:01:00
@@ -34,11 +34,13 @@
FOR
FROM
FULL
+GRAPH_TABLE
GROUP
GROUPING
GROUPS
HASH
HAVING
+IF
IGNORE
IN
INNER
I think the most important characteristic of "parse-unparse" is that it never changes the semantics of the query, but "parse-unparse" can break the semantics of the query.
(*ast.Ident).SQL()
quote identifiers when the identifier is the keyword usingQuoteSQLIdent
.There are bad cases.
It is not a valid query.
So, memefish must maintain
token.Keywords
in keywords.go to match with the official reserved keyword list.It seems that the current diff is
GRAPH_TABLE
andIF
.