diff --git a/CHANGELOG.md b/CHANGELOG.md index fbe46f3..ee28da6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ * 2.5.next in progress * Review metadata -> SQL logic? - * Review quoting logic? + * Address [#515](https://github.com/seancorfield/honeysql/issues/515) in part by quoting entities that start with a digit but are otherwise alphanumeric. Note that entities that are all digits (optionally including underscores) will still not be quoted as in previous releases. * 2.5.1091 -- 2023-10-28 * Address [#512](https://github.com/seancorfield/honeysql/issues/512) by adding support for subqueries in the `:array` special syntax (for BigQuery and PostgreSQL). This also adds support for metadata on the `:select` value to produce `AS STRUCT` or `DISTINCT`. diff --git a/src/honey/sql.cljc b/src/honey/sql.cljc index 6293556..aefe7ce 100644 --- a/src/honey/sql.cljc +++ b/src/honey/sql.cljc @@ -244,8 +244,12 @@ ) (def ^:private alphanumeric - "Basic regex for entities that do not need quoting." - #"^[A-Za-z0-9_]+$") + "Basic regex for entities that do not need quoting. + Either: + * the whole entity is numeric (with optional underscores), or + * the first character is alphabetic (or underscore) and the rest is + alphanumeric (or underscore)." + #"^([0-9_]+|[A-Za-z_][A-Za-z0-9_]*)$") (defn format-entity "Given a simple SQL entity (a keyword or symbol -- or string),