Skip to content
Advertisement

How to insert in two tables in one time? prepared statements

How to insert two table in one time?
I need to insert second table user_information the field user_id with first table user insert returning id, I found this answer but I can’t find how to be with params prepared statements

pg

Advertisement

Answer

Use transactions. That way either all queries will be committed, or none will be committed. And the incomplete state before you have executed all queries is not visible for other processes.

More on how to do transactions in node-postgres is available at https://github.com/brianc/node-postgres/wiki/Transactions

And for reference the most relevant section is:

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement