Fork me on GitHub
#honeysql
<
2023-03-06
>
p-himik07:03:03

Would it make sense to add support for COLLATE to HoneySQL? So e.g. [:collate [:lower :name] :C] results in (LOWER(name)) COLLATE "C". One immediate issue though is that, according to a quick test with SQL Fiddle, different DBs require different syntax: • PostgreSQL requires for the collation name to be quoted • MySQL doesn't care at all • MS SQL Server requires for it to be unquoted I'm using PostgreSQL so currently I have this:

(sql/register-fn! :collate
                  (fn [f [thing collation]]
                    (assert (keyword? collation))
                    (let [result (sql/format-expr thing)]
                      (update result 0
                              (fn [sql]
                                (str "(" sql ") " (sql/sql-kw f) " \"" (name collation) "\""))))))

seancorfield16:03:12

Feel free to create a GitHub issue with links to the various DB docs about it.

👍 2