报错信息:
Caused by: java.io.IOException: Tried to send an out-of-range integer as a 2-byte value: 33048
at org.postgresql.core.PGStream.sendInteger2(PGStream.java:347)
at org.postgresql.core.v3.QueryExecutorImpl.sendParse(QueryExecutorImpl.java:1547)
at org.postgresql.core.v3.QueryExecutorImpl.sendOneQuery(QueryExecutorImpl.java:1872)
at org.postgresql.core.v3.QueryExecutorImpl.sendQuery(QueryExecutorImpl.java:1433)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:315)
postgresql对于sql语句的参数数量是有限制的,最大为32767。
postgresql源码:
public void sendInteger2(int val) throws IOException {
if (val >= -32768 && val <= 32767) {
this.int2Buf[0] = (byte)(val >>> 8);
this.int2Buf[1] = (byte)val;
this.pgOutput.write(this.int2Buf);
} else {
throw new IOException("Tried to send an out-of-range integer as a 2-byte value: " + val);
}
}
从源码中可以看到使用2个字节的integer,故其取值范围为[-32768, 32767]。
这意味着sql语句的参数数量,即行数*列数之积必须小于等于32767。
如果一次插入的数据量太多,使得参数数量超过了最大值,只能分批插入。