Cecilia
Cecilia

Reputation: 3

Is the order preserved when inserting into multiple tables in Postgres

I have 3 tables created and there is no foreign key, so they are not related to each other. In my program, I use JDBC to interact with DB. Now I have a query to insert into each of the table at once:

insert into table1 values (...);
insert into table2 values (...);
insert into table3 values (...);

Can I expect that the insert statements will be executed in order, and then completed in order? In another word, can I expect table1 to have the inserted row first, then table2, and finally table3?

Upvotes: 0

Views: 149

Answers (1)

Mike Organek
Mike Organek

Reputation: 12484

From your program's perspective the inserts will be executed in order.

From outside of your transaction, the inserts will appear simultaneously when your transaction is committed.

Upvotes: 2

Related Questions