honeysql

Discussion of https://github.com/seancorfield/honeysql :slightly_smiling_face:
dharrigan 2020-01-06T11:05:39.024100Z

I have wrote a stored proc :-)

exit2 2020-01-06T18:48:17.024900Z

Hi all, I’m trying to use honeysql to help me write an upsert command in psql

exit2 2020-01-06T18:48:28.025100Z

[INSERT INTO import.spaces (id, import_timestamp, record) VALUES (?, ?, ()), (?, ?, ()), (?, ?, ()) ON CONFLICT (id) DO UPDATE SET record = EXCLUDED.record 43b199b9-0c85-4279-97a4-34bc9abbc653 #inst "2020-01-06T18:47:22.000000000-00:00" fc6b6471-c779-403b-88b6-09b3cdb4cad2 #inst "2020-01-06T18:47:22.000000000-00:00" d02e9a44-751c-45aa-a73b-5c673b79f3ac #inst "2020-01-06T18:47:22.000000000-00:00"]

exit2 2020-01-06T18:49:42.025900Z

When trying to execute this command, I get a syntax error of ERROR: syntax error at or near ")"

exit2 2020-01-06T18:49:59.026100Z

Anyone have any ideas as to why this might be?

exit2 2020-01-06T18:50:29.026400Z

(-> (insert-into table)
                  (values data-vec)
                  (upsert (-> (on-conflict :id)
                              (do-update-set :record)))
                  hsql/format)

exit2 2020-01-06T18:50:34.026600Z

here’s the actual hsql code

bertofer 2020-01-06T18:51:05.027Z

VALUES (?, ?, ()) seems strange, the last element ()

exit2 2020-01-06T18:51:34.027200Z

the vector is something like:

exit2 2020-01-06T18:51:41.027500Z

(def multi-entry
  [{:id (uuid)
    :import_timestamp (now)
    :record {:foo "one"}}
   {:id (uuid)
    :import_timestamp (now)
    :record {:foo "two"}}
   {:id (uuid)
    :import_timestamp (now)
    :record {:foo "three"}}])

exit2 2020-01-06T18:52:19.028Z

is it because that third argument is another hash map?

bertofer 2020-01-06T18:53:05.028500Z

It could be, maybe hsql doesn’t know how to parameterize it and cannot lift it as parameter

exit2 2020-01-06T18:55:53.028700Z

bummer

exit2 2020-01-06T18:58:00.029Z

maybe there is some other way for me to format it so it can work

exit2 2020-01-06T19:31:45.029600Z

I found if I convert the :record or in my case JSON column into a json str, it works

exit2 2020-01-06T19:31:55.029900Z

so it doesn’t have to read the nested hashmap