Arrays
PostgreSQL provides robust support for array data types as column types, function arguments and criteria in where clauses. There are several ways to create arrays with pgjdbc.
The
java.sql.Connection.createArrayOf(String, Object[])
can be used to create an
java.sql.Array
from
Object[]
instances (Note: this includes both primitive and object multi-dimensional arrays).
A similar method
org.postgresql.PGConnection.createArrayOf(String, Object)
provides support for primitive array types.
The
java.sql.Array
object returned from these methods can be used in other methods, such as
PreparedStatement.setArray(int, Array)
.
The following types of arrays support binary representation in requests and can be used in
PreparedStatement.setObject
:
Java Type | Supported binary PostgreSQL Types | Default PostgreSQL Type |
---|---|---|
short[]
,
Short[]
|
int2[]
|
int2[]
|
int[]
,
Integer[]
|
int4[]
|
int4[]
|
long[]
,
Long[]
|
int8[]
|
int8[]
|
float[]
,
Float[]
|
float4[]
|
float4[]
|
double[]
,
Double[]
|
float8[]
|
float8[]
|
boolean[]
,
Boolean[]
|
bool[]
|
bool[]
|
String[]
|
varchar[]
,
text[]
|
varchar[]
|
byte[][]
|
bytea[]
|
bytea[]
|