Replies: 1 comment 1 reply
-
I also have a very simple request of this nature and can not find any documentation anywhere about how to handle it, i can find however, documentation on when it ISNT used. The query is this simple: INSERT INTO customers (contact_name,phone_no,email,address,city, province)
VALUES ("test","test","test","test","test","AB")
RETURNING customer_id; if i use, query_as! with a matching Struct, it doesnt get the customer_id, let insert_customer_query = sqlx::query(&insert_cust_sql)
.bind(job_details.customer_details.name.clone())
.bind(job_details.customer_details.phone.clone())
.bind(job_details.customer_details.email.clone())
.bind(job_details.customer_details.address.clone())
.bind(job_details.customer_details.city.clone())
.bind(job_details.customer_details.province.clone())
.fetch_all(&app_state.db_conn)
.await;
match insert_customer_query {
Ok(data) => println!("ID: {:#?}", data),
Err(e) => println!("e: {e:?}"),
} None of them actually return the values it just show up empty as such
I can see it thinks row returned should be 1, but there is nothing here? There is no value. Is there a discord, or chat server or anything where people who use SQLx hang out? I know this can not be as hard as it seems, and I'm very clearly missing something, please advise, Thank you, |
Beta Was this translation helpful? Give feedback.
-
When I am using sqlx to insert data into the Postgres database, I want to obtain the ID or other information of the data after successful insertion.
For example:
But execute returns a Result<PgQueryResult, Error>, while the PgQueryResult structure only has a u64 attribute and no corresponding method to achieve my goal.
This problem has been bothering me for several days because I am dealing with a multi table and complex operation. If I cannot obtain the ID during insertion, I need to query again, but this will generate a lot of IO operations. I don't know if there is any way to solve it.
Beta Was this translation helpful? Give feedback.
All reactions