We currently store things into Redis for temporary aggregation and have a worker that goes and does insertion in bulk into Postgres. Is there a way that we can do bulk insert across multiple schemas in a single Insert transaction? This will remove the need to aggregate things in Redis. Or, is there a better way to aggregate the requests?
Thanks for the help in advance.
4
Answers
If you execute a insert statement a single transaction will happen and you can only insert in a single table(So inserting across multiple schema is altogether not possible in a single transaction).
It really depends on what you mean with "single insert transaction".
One single
INSERT
statement can only affect one specific table. However you could stillBEGIN
a transaction (depends on implementation), perform all of yourINSERT
in there and thenCOMMIT
the transaction.This would still be more efficient than performing all the
INSERT
s on many transactions since it avoid redundant "hand shakings".https://www.postgresql.org/docs/current/sql-begin.html
Have you tried creating an update-able view that references two tables and then bulk insert in to this view?
Are you looking for something like this?