Skip to main content

Data Types

Data Types Mappings

The table below lists builtin data type mappings.

Posgtres typeJS typeReceiveSend
boolbooleantext,binarybinary
int2numbertext,binarybinary
int4numbertext,binarybinary
int8BigInttext,binarybinary
float4numbertext,binarybinary
float8numbertext,binarybinary
charstringtext,binarybinary
bpcharstringtext,binarybinary
varcharstringtext,binarybinary
dateDatetext,binarybinary
timeDatetext,binarybinary
timestampDatetext,binarybinary
timestamptzDatetext,binarybinary
oidnumbertext,binarybinary
byteaBuffertext,binarybinary
uuidstringtext,binarybinary
jsonobjecttext,binarybinary
jsonbobjecttext,binarybinary
xmlstringtext,binarybinary
pointPointtext,binarybinary
circleCircletext,binarybinary
lsegRectangletext,binarybinary
boxRectangletext,binarybinary
int2Vectornumber[]text,binarybinary
_boolboolean[]text,binarybinary
_int2number[]text,binarybinary
_int4number[]text,binarybinary
_int8BigInt[]text,binarybinary
_float4number[]text,binarybinary
_float8number[]text,binarybinary
_charstring[]text,binarybinary
_bpcharstring[]text,binarybinary
_varcharstring[]text,binarybinary
_dateDate[]text,binarybinary
_timeDate[]text,binarybinary
_timestampDate[]text,binarybinary
_timestamptzDate[]text,binarybinary
_uuidstring[]text,binarybinary
_oidnumber[]text,binarybinary
_byteaBuffer[]text,binarybinary
_jsonobject[]text,binarybinary
_jsonbobject[]text,binarybinary
_xmlstring[]text,binarybinary
_pointPoint[]text,binarybinary
_circleCircle[]text,binarybinary
_lsegRectangle[]text,binarybinary
_boxRectangle[]text,binarybinary
_int2Vectornumber[][]text,binarybinary

Data transfer formats

PostgreSQL wire protocol offers text and binary data transfer formats. Most common libraries supports only text transfer format which is easy to implement but poses performance and memory problems. postgrejs has rich data type mappings which supports both text and binary formats. The default format is set to binary. However, you can set the format to text for all columns or per column.

Note that binary format is faster than text format. If there is a type mapping for that postgres type, we don't suggest you text format.

const qr = await connection.query('select id, other_field from my_table',
{columnFormat: DataFormat.text});
console.log(qr.rows);
const qr = await connection.query('select id, other_field from my_table',
{columnFormat: [DataFormat.binary, DataFormat.text]});
console.log(qr.rows);