Fork me on GitHub
#honeysql
<
2022-05-25
>
Benjamin08:05:25

target output:

SELECT "timestamp" from table
(sql/format {:select '["\"timestamp\""] :from 'table} {:inline true})
  ["SELECT '\"timestamp\"' FROM table"]

seancorfield12:05:03

If you're using PostgreSQL (or some other relatively ANSI-compliant database), that's just normal quoting, so {:select :timestamp :from :table} with {:quoted true}

seancorfield14:05:30

Now I'm at my desk, instead of on my phone:

(! 506)-> clj
Clojure 1.9.0
user=> (require '[honey.sql :as sql])
nil
user=> (sql/format {:select :timestamp :from :table} {:quoted true})
["SELECT \"timestamp\" FROM \"table\""]

seancorfield14:05:37

ANSI/PostgreSQL is the default dialect, but you can get quoting in other dialects too:

user=> (sql/format {:select :timestamp :from :table} {:dialect :mysql})
["SELECT `timestamp` FROM `table`"]
user=> (sql/format {:select :timestamp :from :table} {:dialect :sqlserver})
["SELECT [timestamp] FROM [table]"]

seancorfield14:05:17

(if you specify a :dialect, quoting is enabled by default and you can turn it off with :quoted false; if you have a default dialect -- either ANSI/PostgreSQL out of the box or via set-dialect! or register-dialect! -- then you have to explicitly ask for :quoted true)

👍 1