Fork me on GitHub
#sql
<
2020-02-20
>
bartuka14:02:19

hi, is it possible to make an insert using next.jdbc and get the inserted row back? I have a timestamp column that is created by postgresql and I would like to get this value after insert without the roundtrip of going there again for a select.

dharrigan14:02:49

insert returning?

dharrigan14:02:35

would that not work for you?

dharrigan14:02:09

For example, if you're using honeysql, then https://github.com/nilenso/honeysql-postgres has some extensions

dharrigan14:02:14

one of which is returning

bartuka14:02:58

I would not like to add a new dependency to the project. I am using next.jdbc right now

dharrigan14:02:12

you can hand-craft it if you like

dharrigan14:02:26

but it's a tiny library, so <shrug> reuse, rather than re-invent?

bartuka15:02:36

looks like the return value of sql/insert! already have this information o/

seancorfield15:02:07

You can either pass :return-keys true in the execute! call or use sql/insert! which automatically passes that option in.

seancorfield15:02:56

(although the example just shows the generated keys coming back in H2 -- PostgreSQL returns the entire row... unlike any other database!)

seancorfield15:02:39

I'm adding a note to the PostgreSQL section of Tips &amp; Tricks that PG returns the entire row with either insert! or :return-keys true

parrot 12
dharrigan15:02:59

you're da man!