Re: Bulk Inserts - Mailing list pgsql-general

From Adrian Klaver
Subject Re: Bulk Inserts
Date
Msg-id 9ffb5586-4217-b131-bed8-53b16feb5740@aklaver.com
Whole thread Raw
In response to Re: Bulk Inserts  (Souvik Bhattacherjee <kivuosb@gmail.com>)
Responses Re: Bulk Inserts
List pgsql-general
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@aklaver.com



pgsql-general by date:

Previous
From: Rob Sargent
Date:
Subject: Re: Quoting style (was: Bulk Inserts)
Next
From: "Peter J. Holzer"
Date:
Subject: Re: Recomended front ends?