Question: If an INSERT statement includes a RETURNING Clause, how can I retrieve the returned content?
paulomartins666 opened this issue · 4 comments
paulomartins666 commented
Question: If an INSERT statement includes a RETURNING Clause, how can I retrieve the returned content?
Mause commented
Using the same methods you retrieve results from the database right now?
paulomartins666 commented
the current insert method is to execute through the connection, and the returned result type is the number of rows changed, which seems to indicate the number of rows successfully written. What I mean is, how to get the value of the RETURNING field during insertion, such as the increasing row sequence number.
Mause commented
Like I said, the exact same way you get any other data:
let db = checked_memory_handle();
db.execute_batch("CREATE TABLE foo(x INTEGER);")?;
let re: i64 = db.query_row("INSERT INTO foo(x) VALUES (?) RETURNING x", [1], |r| r.get(0))?;
assert_eq!(res, 1);
paulomartins666 commented
get it,thank u @Mause