PostgreSQL Types
Supported Java types and their destination types on PostgreSQL
All types also support their array versions, but they are returned as IndexedSeq of the type and not
pure Array types.
| PostgreSQL type | Java type |
|---|---|
| boolean | Boolean |
| smallint | Short |
| integer (or serial) | Int |
| bigint (or bigserial) | Long |
| numeric | BigDecimal |
| real | Float |
| double | Double |
| text | String |
| varchar | String |
| bpchar | String |
| timestamp | LocalDateTime |
| timestamp_with_timezone | DateTime |
| date | LocalDate |
| time | LocalTime |
| bytea | Array[Byte] (PostgreSQL 9.0 and above only) |
All other types are returned as String.
Now from Scala/Java types to PostgreSQL types (when using prepared statements):
| Java type | PostgreSQL type |
|---|---|
| Boolean | boolean |
| Short | smallint |
| Int | integer |
| Long | bigint |
| Float | float |
| Double | double |
| BigInteger | numeric |
| BigDecimal | numeric |
| String | varchar |
| Array[Byte] | bytea (PostgreSQL 9.0 and above only) |
| java.nio.ByteBuffer | bytea (PostgreSQL 9.0 and above only) |
| io.netty.buffer.ByteBuf | bytea (PostgreSQL 9.0 and above only) |
| java.util.Date | timestamp_with_timezone |
| java.sql.Timestamp | timestamp_with_timezone |
| java.sql.Date | date |
| java.sql.Time | time |
| LocalDate | date |
| LocalDateTime | timestamp |
| DateTime | timestamp_with_timezone |
| LocalTime | time |
-
Array types are encoded with the kind of object they hold and not the array type itself. Java
Collectionand ScalaTraversableobjects are also assumed to be arrays of the types they hold and will be sent to PostgreSQL like that. -
nullvalues are supported, In prepared statement passnull. -
Spatial / Geometry data types (postgis<->jts) are supported via module
jasync-postgis-jts. In order to use geometry types import the module and init with the following code:
JasyncPostgisRegister.init(connection)