wvlet / airframe

Essential Building Blocks for Scala
https://wvlet.org/airframe
Apache License 2.0
631 stars 65 forks source link

sql (fix): Digit identifier must be quoted #3482

Closed takezoe closed 4 months ago

xerial commented 4 months ago

@takezoe I think DigitIdentifiers are intended for representing GROUP BY 1, 2, 3 .... In which case do we need to quote them?

takezoe commented 4 months ago

I think DigitIdentifiers are intended for representing GROUP BY 1, 2, 3 ...

Ah, I see.

In which case do we need to quote them?

Assuming the following query, "123" is parsed as a digit identifier

SELECT * FROM database."123"

and regenerated SQL from the AST will be invalid:

SELECT * FROM database.123

Now I found the root cause is that a digit identifier is generated in Expression.newIdentifier() for the table name when generate SQL. I will send another PR. https://github.com/wvlet/airframe/blob/eb3c43e72252b3af89548f64e3942daa4eea2bb4/airframe-sql/src/main/scala/wvlet/airframe/sql/model/Expression.scala#L459-L472

takezoe commented 4 months ago

Created https://github.com/wvlet/airframe/pull/3493