Fork me on GitHub
#honeysql
<
2023-05-19
>
Jakub Holý (HolyJak)15:05:40

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!

p-himik15:05:23

Try using [:default] instead of :DEFAULT.

Jakub Holý (HolyJak)15:05:48

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

p-himik15:05:25

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

p-himik15:05:33

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

p-himik15:05:47

[...] is context-dependent.

Jakub Holý (HolyJak)15:05:45

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

p-himik15:05:38

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.

seancorfield16:05:49

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

Jakub Holý (HolyJak)16:05:03

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