Fork me on GitHub
#sql
<
2018-04-17
>
ayato_p00:04:45

Hi. I'm using java.jdbc on my work. I have two questions. 1) shoud I use :multi? option, if I want to insert some records and using :return-keys option? A: (execute! db-spec ["insert into foo (x) values (?), (?)" "x" "y"] {:return-keys true}) vs B: (execute! db-spec ["insert into foo (x) values (?)" ["x"] ["y"]] {:return-keys true :multi? true}) I know, these are differet results. My expectation is B's result, however I want to use A's query. Because Honey SQL don't support :multi? option and A is fast. 2) Why :return-keys should not work correctlly. foo table has two columns, x and y, and I just needs x column. So, I wrote the code like this. (execute! db-spec ["insert into foo (x, y) values (?, ?)" "x" "y"] {:return-keys ["x"]}) But, I got a result as {:x "x", :y "y"}. If I use prepare-statement directly, it works. Is this a correct behavior?

hiredman00:04:47

execute! doesn't have a :return-keys option, which is why it has no effect when you pass one in

hiredman00:04:33

the only options execute! takes are :multi? and :transaction?

hiredman00:04:14

have you tried using insert-rows! ? if I recall that just returns a collection of the inserted keys

hiredman01:04:12

what version of java.jdbc are you using?

hiredman01:04:25

I was looking at an old check I had, which is why I said execute! doesn't take that option, if you are seeing it behave as if execute! doesn't have that option maybe you are using an old version where it doesn't

ayato_p01:04:34

You mean, insert-multi! ? I don't want to use this. Because I'm using Honey SQL and HugSQL and so on.

ayato_p01:04:50

Ah, java.jdbc 0.7.5

hiredman01:04:07

do you have an example of prepare-statement giving you the behavior you want?

hiredman01:04:17

from what I can see, the behavior of returning keys is largely determined by the underlying jdbc driver

hiredman01:04:41

execute! just passes the result-set to a function that generates a seq of maps from it

hiredman01:04:30

come to think of it, where are the generated keys in your example?