Closed xinglin-zhao closed 1 week ago
can you show documentation that allows 3b as a column name without quotes?
you need to specify the dialect select("3b", dialect="databricks").
this works as expected
Thanks Toby. Two questions:
dialect="databricks"
on every statement, it seems a bit verbose, any suggestions? right, the default dialect treats 3b like 3 as b. i suggest writing the default dialect of using the builder
right, the default dialect treats 3b like 3 as b. i suggest writing the default dialect of using the builder
do you have any example of setting default dialect of using the builder. often our style starts with an empty Select expression, but setting dialect at Select doesn't work as default.
from sqlglot import exp, parse_one, expressions
query = expressions.Select(dialect='databricks')
query = query.select("3b")
query = query.select("3b", dialect='databricks')
query.sql(dialect="databricks")
result: 'SELECT 3 AS b, 3b'
no that isn’t supported
i see. if you have some good examples for this type of issue, please let me know. I can circulate them and make sure we are using sqlglot in a preferred way.
the fix is something like, basically builds an expression. i think one learning is we should always use expression if possible.
column = expressions.Identifier(this="3b")
query = query.select(column)
Fully reproducible code snippet The below is one example,
expression_tree.select("3b")
is parsed as3 AS b
, which is not intended. Please help fix or add checks such as not allowing column names starting with a number. For our use case, names like3b
are valid.This is the sqlglot version we are using
Successfully installed sqlglot-23.11.2