Types supported out of the box

This section contains a list of base type names and names of built-in range types understood by DefaultTypeConverterFactory, those can be converted without setting up the Connection. This allows using the factory separately e.g. with PDO.

The preconfigured mappings from PHP class names to database types are also given.

Type names known to DefaultTypeConverterFactory

Note the following when reading the table:

  • Type names in lowercase are PostgreSQL’s internal, corresponding to rows in pg_catalog.pg_type. Those in UPPERCASE are their SQL standard synonyms.

  • sad_spirit\pg_wrapper\converters namespace prefix is assumed for all converter class names.

  • sad_spirit\pg_wrapper\types namespace prefix is assumed for all complex type class names that do not start with a backslash.

  • “Compatible array” is an array that will be accepted by createFromArray() method of type’s class.

Base types

Type names

TypeConverter implementation

Non-null PHP value returned

Non-null PHP values accepted

bool, BOOLEAN

BooleanConverter

bool

anything, PHP values evaluating to false and strings 'false' and 'f' are converted to 'f', everything else to 't'

bytea

ByteaConverter

string (binary)

string (binary)

cstring, text, char, varchar, bpchar, name, CHARACTER, NCHAR, CHAR VARYING, CHARACTER VARYING, BIT VARYING, NCNAR VARYING, NATIONAL CHAR VARYING, NATIONAL CHARACTER VARYING

StringConverter

string

string

oid, cid, xid, int2, int4, int8, INT, INTEGER, SMALLINT, BIGINT

IntegerConverter

int, numeric-string if integer is out of range for PHP (e.g. int8 type on 32-bit PHP)

numeric values

numeric, money DECIMAL, DEC

NumericConverter

string, to prevent loss of precision

float4, float8 REAL, FLOAT, DOUBLE PRECISION

FloatConverter

float

json, jsonb

JsonConverter

usually an array

anything json_encode() can handle

date

datetime\DateConverter

instance of \DateTimeImmutable

  • instance of \DateTimeInterface

  • string (passed as is)

  • int (treated as UNIX timestamp)

time, TIME WITHOUT TIME ZONE

datetime\TimeConverter

timetz, TIME WITH TIME ZONE

datetime\TimeTzConverter

timestamp, TIMESTAMP WITHOUT TIME ZONE

datetime\TimeStampConverter

timestamptz, TIMESTAMP WITH TIME ZONE

datetime\TimeStampTzConverter

interval

datetime\IntervalConverter

instance of \DateInterval

  • instance of \DateInterval

  • int / float (treated as number of seconds)

  • string (passed as is)

json, jsonb

JsonConverter

usually an array

anything json_encode() can handle

box

geometric\BoxConverter

instance of Box

instance of Box or compatible array

circle

geometric\CircleConverter

instance of Circle

instance of Circle or compatible array

line

geometric\LineConverter

instance of Line

instance of Line or compatible array

lseg

geometric\LSegConverter

instance of LineSegment

instance of LineSegment or compatible array

path

geometric\PathConverter

instance of Path

instance of Path or compatible array

point

geometric\PointConverter

instance of Point

instance of Point or compatible array

polygon

geometric\PolygonConverter

instance of Polygon

instance of Polygon or compatible array

tid

TidConverter

instance of Tid

instance of Tid or compatible array

hstore (from contrib/hstore extension)

container\HstoreConverter

array<string,?string>

array or object

int2vector, oidvector

containers\IntegerVectorConverter

list<int|numeric-string>

single-dimension array of numeric values

Built-in range and multirange types

Type names

TypeConverter implementation

Non-null PHP value returned

Non-null PHP values accepted

int4range, int8range

\containers\RangeConverter with IntegerConverter

instance of NumericRange

instance of NumericRange or compatible array

numrange

\containers\RangeConverter with NumericConverter

daterange

\containers\RangeConverter with datetime\DateConverter

instance of DateTimeRange

instance of DateTimeRange or compatible array

tsrange

\containers\RangeConverter with datetime\TimeStampConverter

tstzrange

\containers\RangeConverter with datetime\TimeStampTzConverter

int4multirange, int8multirange

\containers\MultiRangeConverter with IntegerConverter

instance of NumericMultiRange

instance of NumericMultiRange or compatible array

nummultirange

\containers\MultiRangeConverter with NumericConverter

datemultirange

\containers\MultiRangeConverter with datetime\DateConverter

instance of DateTimeMultiRange

instance of DateTimeMultiRange or compatible array

tsmultirange

\containers\MultiRangeConverter with datetime\TimeStampConverter

tstzmultirange

\containers\MultiRangeConverter with datetime\TimeStampTzConverter

Classes mapped to database types

Passing instances of the below classes (sad_spirit\pg_wrapper\types namespace prefix is assumed for all names that do not start with a backslash) as query parameters does not require specifying parameter types. Converters for database types in the second column will be used.

Class name

Database type

\DateTimeInterface

timestamptz

\DateInterval

interval

Box

box

Circle

circle

Line

line

LineSegment

lseg

Path

path

Point

point

Polygon

polygon

DateTimeRange

tstzrange

DateTimeMultiRange

tstzmultirange

NumericRange

numrange

NumericMultiRange

nummultirange

Tid

tid