duckdb/duckdb-rs

Question: If an INSERT statement includes a RETURNING Clause, how can I retrieve the returned content?

paulomartins666 opened this issue · 4 comments

Question: If an INSERT statement includes a RETURNING Clause, how can I retrieve the returned content?

Using the same methods you retrieve results from the database right now?

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.

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);

get it,thank u @Mause