From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Souvik Bhattacherjee <kivuosb@gmail.com>
Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: Bulk Inserts
Date: Sun, 11 Aug 2019 08:11:10 -0700
Message-ID: <9ffb5586-4217-b131-bed8-53b16feb5740@aklaver.com> (raw)
In-Reply-To: <CAANrPSf0bHm0BwezBcLjP9DfTdqd2Tdh8WdcKQ7n3=aop32fvA@mail.gmail.com>
References: <CAANrPSeVe5UNdLTm5STHdjPad89VbAZ_0UGcR_Cvo8_OqF91fA@mail.gmail.com>
<bc6d54b9-a5b0-d974-1247-d9aa2272450f@aklaver.com>
<CAANrPSf0bHm0BwezBcLjP9DfTdqd2Tdh8WdcKQ7n3=aop32fvA@mail.gmail.com>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: adrian.klaver@aklaver.com, kivuosb@gmail.com
Subject: Re: Bulk Inserts
In-Reply-To: <9ffb5586-4217-b131-bed8-53b16feb5740@aklaver.com>
References: <CAANrPSeVe5UNdLTm5STHdjPad89VbAZ_0UGcR_Cvo8_OqF91fA@mail.gmail.com> <bc6d54b9-a5b0-d974-1247-d9aa2272450f@aklaver.com> <CAANrPSf0bHm0BwezBcLjP9DfTdqd2Tdh8WdcKQ7n3=aop32fvA@mail.gmail.com> <9ffb5586-4217-b131-bed8-53b16feb5740@aklaver.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox