sqlparse
sqlparse copied to clipboard
Change in identifier case during reformatting
First, thanks for a great and useful package.
I am seeing an identifier change case during transform. Possibly this is my fault as I don't know how to tell sqlparse
what the identifier and string quotes are. The back-tick identifier quotes are for use with Google BigQuery.
My example is as follows. Notice how data-algebra-test.test_1.d
changed to DATA-algebra-test.test_1.d
.
import sqlparse
sqlparse.__version__
# '0.4.1'
sql = "SELECT (`x` = -`x`) AS `x_is_bad` FROM `data-algebra-test.test_1.d`"
sqlparse_options = {"reindent": True, "keyword_case": "upper"}
formatted_sql = sqlparse.format(
sql, **sqlparse_options
)
print(formatted_sql)
# SELECT (`x` = -`x`) AS `x_is_bad` FROM `DATA-algebra-test.test_1.d`
assert 'DATA' not in formatted_sql
Hello there, I have exactly the same behavior. DATA is reconized as a keyword and is put in uppercase, but this iw messing with the project/dabatase name in Big Query. What is DATA used for as a keyword ? It seems not to be used in all SQL languages ?
The best scenario would be to be able to send a list of keywords to buypass.
My SQL :
CREATE OR REPLACE VIEW data-project.data-universes-eu.fact_exchange_rates
=> is traformed as : CREATE OR REPLACE VIEW DATA-project.data-universes-eu.fact_exchange_rates
wich is not undestrood by Big Query as the project id should be lowercase