3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

PostgreSQLのJDBCはバインドできるパラメーター数に限界がある

Posted at

ずいぶん昔の事ですが、
JavaでListに入った条件の数だけIN (?)バインドパラメーターを増やすような実装で
条件を増やし続けると次のようなIOExceptionthrowされるという事象がありました。

 java.io.IOException: Tried to send an out-of-range integer as a 2-byte value: 32768

この問題に遭遇したのはかなり昔の事ですが、当時は何らかのデータ量制限に引っかかったのだろうと思い
IN(?)の使用を取りやめてカラム名 = ANY(?)にSQLステートメントを変更、
パラメーターをjava.sql.Arrayに変換する事でパラメーター数を押さえたら
エラーが発生しなくなったのでそれ以上の深追いはしていませんでした。

この事象を思い出したので調べてみると、
どうやらPostgreSQLサーバーとの通信プロトコルのパラメーター数が2バイトを超える数値に対応していないようです。

GitHubにもissueが存在しました。

この制約はorg.postgresql.core.PGStream#sendInteger2(int)に書かれており
パラメーター数に限らず、sendInteger2(int)でサーバーにデータを送る処理は32,767を超えることが出来ないようです。

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?