Skip to content
developed by

Data types

WARNING

Whereas the supported type list is still valid, this page is mostly outdated and will be replaced by the value converter page.

Rationale

Data types are purely informational: the user may or may not specify its value types when adding parameters to the query.

It will be exposed later to the bridge that will execute the queries.

For rationalisation and consistency, it is advised that you stick the to following data type matrix.

Every type has a unique identifier, for example int which reprensents an integer, and a set of type aliases, for example int4 refers to int.

Data type matrix

TypeAliasesPHP Native typeSQL typeNotes
bigintint8intbigintsize (32 or 64 bits) depends on your arch
bigserialserial8intbigserialsize (32 or 64 bits) depends on your arch
boolbooleanboolboolean
byteablobstring or resourcebyteasome drivers will give you a resource instead of a string
date\DateTimeInterfacedatePHP has no date type, timezone might cause you trouble
decimalnumericfloatdecimal
float4realfloatfloat4May loose precision
float8realfloatfloat8
intint4intintsize (32 or 64 bits) depends on your arch
interval\DateIntervalintervalyou probably will need to deambiguate from time
jsonjsonbarrayjsondifference between json and jsonb is in storage
serialserial4intserialsize (32 or 64 bits) depends on your arch
time\DateIntervaltimeyou probably will need to deambiguate from interval
timestampdatetime\DateTimeInterfacetimestamp
ulid\Symfony\Component\Uid\Uliduuidyou will need to install symfony/uid in order to use it
uuid\Ramsey\Uuid\UuidInterfaceuuidyou will need to install ramsey/uuid in order to use it
uuid\Symfony\Component\Uid\Uuiduuidyou will need to install symfony/uid in order to use it
varchartextstringvarchar or text

ARRAY

All types without exception can be manipulated as value-arrays. In order to cast values as typed arrays, use the form TYPE[], for example: int[].

When you want to pass an array of values into your parameters, just pass the value transparently:

php
use MakinaCorpus\QueryBuilder\Writer\Writer;

assert($writer instanceof Writer);

$writer->prepare(
    <<<SQL
    insert into foo (my_array) values (?)",
    SQL,
    [
        [1, 2, 3],
    ]
);