honeysql

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!

p-himik 2023-05-19T15:20:23.081519Z

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?

p-himik 2023-05-19T15:21:25.920559Z

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

p-himik 2023-05-19T15:21:33.965379Z

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

p-himik 2023-05-19T15:21:47.275909Z

[...] 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
p-himik 2023-05-19T15:24:38.560899Z

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.

seancorfield 2023-05-19T16:15:09.427389Z

I don't want to be that guy but... https://cljdoc.org/d/com.github.seancorfield/honeysql/2.4.1026/doc/getting-started/sql-special-syntax-#constraint-default-references has examples 🙂

seancorfield 2023-05-19T16:15:49.228089Z

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 😅

seancorfield 2023-05-19T16:17:26.988239Z

Feel free to add notes to https://github.com/seancorfield/honeysql/issues/489