This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-06-20
Channels
- # ai (4)
- # aleph (1)
- # babashka (127)
- # beginners (89)
- # calva (44)
- # cider (22)
- # clerk (74)
- # clj-commons (5)
- # clj-kondo (3)
- # cljs-dev (51)
- # clojure (117)
- # clojure-europe (22)
- # clojure-nl (2)
- # clojure-norway (100)
- # clojure-uk (2)
- # clojurescript (64)
- # data-science (26)
- # datalevin (3)
- # datascript (2)
- # emacs (10)
- # events (5)
- # figwheel-main (12)
- # helix (2)
- # honeysql (15)
- # hoplon (3)
- # jobs-discuss (32)
- # malli (3)
- # polylith (3)
- # re-frame (2)
- # reitit (15)
- # releases (2)
- # sci (14)
- # shadow-cljs (14)
- # specter (2)
- # tools-build (7)
- # xtdb (16)
Hello again! I am at a loss, again 😅 How do I generate
... ON CONFLICT (date_trunc('month', "my_column")) DO ...
? https://cljdoc.org/d/com.github.seancorfield/honeysql/2.4.1033/api/honey.sql.helpers?q=on-conf#on-conflict does not help me… 🙏 🙏 🙏Doesn't seem like there's a way to do it without putting the whole ON CONFLICT
into :raw
, so might be something that warrants HoneySQL's DSL extension.
@U0522TWDA I'm fixing this so that this works:
user=> (sql/format {:on-conflict [[:date_trunc [:inline "month"] :my_column]]} {:quoted true})
["ON CONFLICT DATE_TRUNC('month', \"my_column\")"]
Does it specifically need those (
.. )
around the expression to be valid syntax?
https://github.com/seancorfield/honeysql/issues/494 (I'm going to assume it does need the parens).
Here's how it works now on the latest develop or the latest SNAPSHOT on Clojars:
user=> (sql/format {:on-conflict [:a [:date_trunc [:inline "month"] :my_column] :b]} {:quoted true})
["ON CONFLICT (\"a\", DATE_TRUNC('month', \"my_column\"), \"b\")"]
I'll cut a new release before the end of the month. Not sure what else I'll end up fixing in that release right now.
Not sure how to test it properly given that I can't use date_trunc
in ON CONFLICT
without also creating an index on it, and I can't create an index on it because the function is not marked as immutable.
But given the syntax description of INSERT
, it seems that you need an extra pair of parents around expressions in ON CONFLICT
.
Just tried it with col + 1
expression instead of date_trunc
- yep, needs extra parens, so the above should be formatted as ON CONFLICT ("a", (DATE_TRUNC('month', "my_column")), "b")
.
If it's any help, at least in the case of PostgreSQL the whole part after ON CONFLICT
follows the CREATE INDEX
format as per the docs.
Oh, interesting... it needs parens inside the group too??
(and, no, matching create index
doesn't help at all 🙂 )
Yeah, otherwise stuff like INSERT INTO t VALUES (1) ON CONFLICT (d + 1) DO NOTHING;
fails with ERROR: syntax error at or near "+" Position: 41
. Using ((d + 1))
works.
Fix pushed to GH. A new SNAPSHOT will be available "soon".
Sorry for the late reply. I see you figured everything out. Many thanks to both of you! I'll try the snapshot ASAP