This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-07-29
Channels
- # babashka (64)
- # beginners (60)
- # calva (10)
- # circleci (3)
- # clj-kondo (62)
- # cljdoc (6)
- # clojars (2)
- # clojure (152)
- # clojure-europe (19)
- # clojure-nl (3)
- # clojure-uk (18)
- # clojurescript (50)
- # clojureverse-ops (12)
- # core-async (21)
- # cursive (6)
- # data-science (1)
- # datomic (17)
- # events (14)
- # fulcro (64)
- # graalvm (20)
- # graphql (5)
- # honeysql (14)
- # jackdaw (3)
- # jobs (1)
- # jobs-discuss (22)
- # kaocha (2)
- # lsp (9)
- # luminus (8)
- # malli (30)
- # meander (31)
- # other-languages (1)
- # polylith (8)
- # re-frame (15)
- # shadow-cljs (85)
- # specter (2)
- # sql (11)
- # tools-deps (56)
- # vim (39)
- # vscode (7)
- # xtdb (16)
Hey all, need to upsert this key value pair
:key "1234567",
:value {:val-a "hello", :val-b ["ABC" "XYZ" "PQR"], :val-c "MNO", :val-d ["RST"]}
in postgres using honeysql
where value should be in jsonb format and key being stringThere's no need to cross-post in both #honeysql and #sql -- tell us what you've tried and what didn't work and what actual question you have. I've already pointed you at the documentation -- have you read it? Does it not answer your question?
Right, so explain what you've tried and where the docs fall short for you.
You're being lazy. Both the honeysql project and the next.jdbc project link to the documentation.
Hey @U04V70XH6, I am using https://github.com/nilenso/honeysql-postgres#upsert for upserting this data in my postgres database. The table has this schema:
CREATE TABLE my_table (
key varchar(150) NOT NULL,
value jsonb,
PRIMARY KEY (key)
);
My clojure code looks like this:
(defn upsert!
[table record constraint-name where-clause]
(-> (insert-into table)
(values [record])
(where* where-clause)
(psqlh/upsert (-> (psqlh/on-conflict-constraint constraint-name)
(psqlh/do-update-set :key
:value)
))
sql/format)
But I am getting this error on calling the upsert function on the same key twice :
2021-07-30 19:42:30.656 UTC [2376] ERROR: duplicate key value violates unique constraint "my_table_pkey"
2021-07-30 19:42:30.656 UTC [2376] DETAIL: Key (key)=(8343847329) already exists.
2021-07-30 19:42:30.656 UTC [2376] STATEMENT: INSERT INTO my_table (driver_id, tags) VALUES ($1, $2)
As per the doc the query in postgres should look like below :
["INSERT INTO distributors (did, dname) VALUES (?, ?), (?, ?) ON CONFLICT (did) DO UPDATE SET dname = EXCLUDED.dname RETURNING *"
5 "Gizmo Transglobal" 6 "Associated Computing, Inc"]
nilenso/honeysql-postgres
PostgreSQL extension for honeysql
Website
http://nilenso.com
Stars
180
The following query works fine when executed directly in the psql shell.
INSERT INTO my_table (key, value) VALUES ('8343847329', '{"val-a": "hello", "val-b": ["ABC" "XYZ" "PQR"], "val-c": "MNO", "val-d": ["RST"]}') ON CONFLICT (key) DO UPDATE SET value = EXCLUDED.value RETURNING *;
I feel my clojure code is unable to create the appropriate DML for the expected psql query.You can only use the old 1.x version of HoneySQL with that nilenso library. If you use the 2.x version of HoneySQL, you don't need the nilenso library, but the HoneySQL syntax is slightly different. See https://cljdoc.org/d/com.github.seancorfield/honeysql/2.0.0-rc5/doc/getting-started/postgresql-support