sfackler / rust-postgres

Native PostgreSQL driver for the Rust programming language
Apache License 2.0
3.42k stars 436 forks source link

Get primary key when inserting #1100

Closed JJaviMS closed 6 months ago

JJaviMS commented 6 months ago

Hi, I am trying to perform an insertion in a transaction where an insertion depends on a previously inserted primary key (with a FK constraint). As far as I can see, the execute method only returns the number of updates columns. Is there a way to get the inserted primary key?

For example in Java this is possible by using JDBC.

sfackler commented 6 months ago

Use client.query_one("INSERT INTO ... VALUES (...) RETURNING id")

JJaviMS commented 6 months ago

It worked perfectly. Thank you!