Top
Enterprise Postgres 17 SP1 Application Development Guide

2.4.1 Relationship between the Application Data Types and Database Data Types

The following table shows the correspondence between data types in applications and data types in databases.

Data type on the server

Java data type

Data types prescribed by java.sql.Types

character

String

java.sql.Types.CHAR

national character

String

java.sql.Types.NCHAR

character varying

String

java.sql.Types.VARCHAR

national character varying

String

java.sql.Types.NVARCHAR

text

String

java.sql.Types.VARCHAR

bytea

byte[]

java.sql.Types.BINARY

smallint

short

java.sql.Types.SMALLINT

integer

int

java.sql.Types.INTEGER

bigint

long

java.sql.Types.BIGINT

smallserial

short

java.sql.Types.SMALLINT

serial

int

java.sql.Types.INTEGER

bigserial

long

java.sql.Types.BIGINT

real

float

java.sql.Types.REAL

double precision

double

java.sql.Types.DOUBLE

numeric

java.math.BigDecimal

java.sql.Types.NUMERIC

decimal

java.math.BigDecimal

java.sql.Types.DECIMAL

money

String

java.sql.Types.OTHER

date

java.sql.Date

java.sql.Types.DATE

time with time zone

java.sql.Time

java.sql.Types.TIME

time without time zone

java.sql.Time

java.sql.Types.TIME

timestamp without time zone

java.sql.Timestamp

java.sql.Types.TIMESTAMP

timestamp with time zone

java.sql.Timestamp

java.sql.Types.TIMESTAMP

interval

org.postgresql.util.PGInterval

java.sql.Types.OTHER

boolean

boolean

java.sql.Types.BIT

bit

boolean

java.sql.Types.BIT

bit varying

org.postgresql.util.Pgobject

java.sql.Types.OTHER

oid

long

java.sql.Types.BIGINT

xml

java.sql.SQLXML

java.sql.Types.SQLXML

array

java.sql.Array

java.sql.Types.ARRAY

uuid

java.util.UUID

java.sql.Types.OTHER

point

org.postgresql.geometric.Pgpoint

java.sql.Types.OTHER

box

org.postgresql.geometric.Pgbox

java.sql.Types.OTHER

lseg

org.postgresql.geometric.Pglseg

java.sql.Types.OTHER

path

org.postgresql.geometric.Pgpath

java.sql.Types.OTHER

polygon

org.postgresql.geometric.PGpolygon

java.sql.Types.OTHER

circle

org.postgresql.geometric.PGcircle

java.sql.Types.OTHER

json

org.postgresql.util.PGobject

java.sql.Types.OTHER

Network address type (inet,cidr,macaddr, macaddr8)

org.postgresql.util.PGobject

java.sql.Types.OTHER

Types related to text searches (svector, tsquery)

org.postgresql.util.PGobject

java.sql.Types.OTHER

Enumerated type

org.postgresql.util.PGobject

java.sql.Types.OTHER

Composite type

org.postgresql.util.PGobject

java.sql.Types.OTHER

Range type

org.postgresql.util.PGobject

java.sql.Types.OTHER

Although the getString() method of the ResultSet object can be used for all server data types, it is not guaranteed that it will always return a string in the same format for the same data type.

Strings in a format compatible with the JDBC specifications can be obtained using the Java toString() method of the appropriate data type (for example, getInt(), getTimestamp()) to conform to the data type on the server.