How does postgresql jdbc driver implement prepared batch?

Поиск
Список
Период
Сортировка
От Jinhua Luo
Тема How does postgresql jdbc driver implement prepared batch?
Дата
Msg-id CAAc9rOwTZ3d6=YUV-vJPndebVyUGAz_Pk8WV1fYkmpVykttLug@mail.gmail.com
обсуждение исходный текст
Список pgsql-general
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


В списке pgsql-general по дате отправления:

Предыдущее
От: Andreas Joseph Krogh
Дата:
Сообщение: Re: Initdb --data-checksums by default
Следующее
От: Alex Ignatov
Дата:
Сообщение: Re: Initdb --data-checksums by default