Search Postgresql Archives

Re: Bulk Inserts

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 8/10/19 7:47 PM, Souvik Bhattacherjee wrote:
Hi Adrian,

Thanks for the response.

 > Yes, but you will some code via client or function that batches the
 > inserts for you.

Could you please elaborate a bit on how EXP 1 could be performed such that it uses bulk inserts?

I guess it comes down to what you define as bulk inserts. From your OP:

EXP 1: inserts with multiple txn:
insert into tab2 (attr1, attr2) (select attr1, attr2 from tab1 where attr2 = 10); insert into tab2 (attr1, attr2) (select attr1, attr2 from tab1 where attr2 = 20);

If the selects are returning more then one row then you are already doing bulk inserts. If they are returning single rows or you want to batch them then you need some sort of code to do that. Something like(pseudo Python like code):

attr2_vals= [(10, 20, 30, 40), (50, 60, 70, 80)]

for val_batch in attr2_vals:
	BEGIN
	for id in val_batch:
		insert into tab2 (attr1, attr2) (select attr1, attr2
                from tab1 where attr2 = id)
        COMMIT


Best,
-SB



--
Adrian Klaver
adrian.klaver@xxxxxxxxxxx





[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux