Re: [GENERAL] How does postgresql jdbc driver implement prepared batch?

From: Dave Cramer <pg(at)fastcrypt(dot)com>
To: Jinhua Luo <luajit(dot)io(at)gmail(dot)com>
Cc: List <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: [GENERAL] How does postgresql jdbc driver implement prepared batch?
Date: 2016-04-24 23:13:43
Message-ID: CADK3HHJmPpKyiD3mcZAWiztPpJ0edBhO1qwk5kjdrWnANSgs6w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-jdbc

You will get considerably more response if you use the jdbc list.

The driver does not change it to a "final statement" it creates the
prepared statement then sets the parameters many times and executes it,

Although the most recent code does it a bit differently now

Dave Cramer

davec(at)postgresintl(dot)com
www.postgresintl.com

On 20 April 2016 at 07:08, Jinhua Luo <luajit(dot)io(at)gmail(dot)com> wrote:

> Hi,
>
> As document said, in the extended query protocol, "The query string
> contained in a Parse message cannot include more than one SQL
> statement".
>
> So to support batch in prepared statement, I think the only way is to
> determine the batch size in advance and then create the appropriate
> prepared statement, e.g.
>
> Given the batch size is fixed to 3, then prepare below statement:
> -- create table foobar(a int, b text);
> insert into foobar values($1, $2), ($3, $4), ($5, $6);
>
> Then this prepared statement must be bound with 3 set of arguments.
>
> The limitation is obvious: the batch size is fixed, so if you need to
> do batch with size of 4, the previous prepared statement is useless
> and you need to recreate it.
>
> On the other hand, in JDBC, it seems that you just need to prepare
> below statement:
>
> insert into foobar values($1, $2);
>
> And then calls addBatch() repeatedly until you think the batch size is
> enough.
>
> What's the final statement does postgresql jdbc driver convert to? I'm
> so curious.
>
> I'm not familiar with jdbc, and although I check the driver source
> codes, but I still cannot understand it.
>
> Anybody knows the answer? Thanks.
>
>
> Regards,
> Jinhua Luo
>
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message david 2016-04-25 05:18:30 Background worker plus language handler for Andl: OK?
Previous Message Karsten Hilbert 2016-04-24 16:18:04 Re: Is it possible to recover the schema from the raw files?

Browse pgsql-jdbc by date

  From Date Subject
Next Message Dave Cramer 2016-04-25 10:45:35 Re: [GENERAL] How does postgresql jdbc driver implement prepared batch?
Previous Message Dave Cramer 2016-04-24 23:10:42 Re: Kerberos problem with pg_ident that happens with JDBC but not with PSQL.