honeysql 2023-05-19

Jakub Holý (HolyJak) 2023-05-19T15:14:40.387619Z

Hi! How do I tell Honey that DEFAULT is a Postgres keyword and not a column name that should be quoted? This

(-> (hh/update table)
      (hh/set {:col :DEFAULT})
      (honey.sql/format {:quoted true}))
produces UPDATE "snapshot" SET "col" = "DEFAULT" while I need UPDATE "snapshot" SET "col" = DEFAULT . I did not find anything in the docs other than [:raw "DEFAULT"] . Is that it, or is there a better way? Thank you!

Try using [:default] instead of :DEFAULT.

Jakub Holý (HolyJak) 2023-05-19T15:20:48.596649Z

Doesn’t that produce default() which is a function call?

You're a single REPL execution away from checking. ;)

(sql/format {:update :t 
             :set    {:col [:default]}})
=> ["UPDATE t SET col = DEFAULT"]

[...] is context-dependent.

Jakub Holý (HolyJak) 2023-05-19T15:22:45.793789Z

You are right. Sometimes I feel HoneySQL is too magic and beyond my understanding… 😅

Jakub Holý (HolyJak) 2023-05-19T15:22:52.331739Z

thanks a lot!

👍 1

Addendum to my "context-dependent" message - [...] is also content-dependent. E.g. :default in a vector expands to DEFAULT but :x expands to x(). So in this case it's just that HoneySQL treats :default in a special way.

But, yes, the docs for :update could certainly be beefed up...

Jakub Holý (HolyJak) 2023-05-19T16:17:03.218289Z

Ah, I have been on the page but haven't thought of searching it for default 😅