Tuesday 27 December 2016

Batching queries to postgres to minimize roundtrips from the application

Is there a way to batch various queries to postgres from node so that you minimize roundtrips to the database?The only thing I can think of is to use the multi-insert query like insert into sometable(column1) values (1), (2), (3) which would insert 3 rows in one round trip. But let's say I want to do something like thisinsert into table1(column1) values (1), (2), (3) insert into anothertable(column1) values (1), (2), (3) insert into thirdtable(column1) values (1), (2), (3) how can I do it in one round trip? It's slowing things down with all the unnecessary roundtrips. I can wrap it all in a begin and commit so that the 3 statements above are run as a transaction, all-or-nothing. But that doesn't eliminate the extra roundtrips.I'm not using any ORMs or anything like that, and would like to stay away from it if possible. I'm using http://ift.tt/1BYQ4u6 to connect to postgres from node.

Submitted December 27, 2016 at 06:07PM by nowboarding

No comments:

Post a Comment