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.
insert returning?
yes
would that not work for you?
For example, if you're using honeysql, then https://github.com/nilenso/honeysql-postgres has some extensions
one of which is returning
I would not like to add a new dependency to the project. I am using next.jdbc
right now
you can hand-craft it if you like
but it's a tiny library, so <shrug> reuse, rather than re-invent?
looks like the return value of sql/insert!
already have this information o/
You can either pass :return-keys true
in the execute!
call or use sql/insert!
which automatically passes that option in.
@iagwanderson Read "Getting Started" https://cljdoc.org/d/seancorfield/next.jdbc/1.0.13/doc/getting-started#execute--execute-one -- it has an example of this exact thing! 🙂
(although the example just shows the generated keys coming back in H2 -- PostgreSQL returns the entire row... unlike any other database!)
I'm adding a note to the PostgreSQL section of Tips & Tricks that PG returns the entire row with either insert!
or :return-keys true
you're da man!
thanks!