Fork me on GitHub

Hello guys! Is it possible to use lower case table names when constructing create-table query? For example I have a table in my Postgres - "user" quoted, so in all my queries I should use a lover case name And I’m trying to do something like this

(sql/format {:create-table :table
             :with-columns [[:user :uuid [:references :user]]]}
            {:quoted true})
which gives me ["CREATE TABLE \"table\" (\"user\" \"UUID\" REFERENCES \"USER\")"] string with upper case "USER" as a table name. But Postgres doesn’t recognize it as an existing table user. and I see that HoneySQL is calling upper-case function for all columns here.


There's no real good solution right now but it's something I'm looking at because the logic around DDL creation and casing is... a bit of a hack. If you're on a recent version of HoneySQL, you could try [:references :'user] which should treat user as something literal but will probably not quote the name.


As I suspected, using the "literal name" escape hatch also (deliberately) avoids quoting:

user=> (sql/format {:create-table :table
             :with-columns [[:user :uuid [:references :'user]]]}
            {:quoted true})
["CREATE TABLE \"table\" (\"user\" \"UUID\" REFERENCES user)"]


Thanks, but I think Postgres wouldn’t accept that as user is a reserved keyword and have to be quoted


I ended up with some custom clause for now

(defn format-raw-update [_ x]
  [(str "UPDATE " (first (sql/format-expr [:inline x])))])

(sql/register-clause! :update-raw format-raw-update :update)


seems a little bit hacky but it works. Will wait for a proper solution. :thumbsup:


Is there a way to tell HoneySQL to leave the column name in lower case?