Skip to main content
Version: v2.x

Postgres: Supported types

Introduction

List of PostgreSQL types supported by the Hasura GraphQL engine with their equivalent Hasura types:

NameAliasesDescriptionHasura Type
bigintint8signed eight-byte integerNumeric or String (flag)
bigserialserial8autoincrementing eight-byte integerNumeric or String (flag)
bit [ (n) ]fixed-length bit stringImplicit
bit varying [ (n) ]varbit [ (n) ]variable-length bit stringImplicit
booleanboollogical Boolean (true/false)Bool
boxrectangular box on a planeImplicit
byteabinary data (“byte array”)Implicit
character [ (n) ]char [ (n) ]fixed-length character stringChar
character varying [ (n) ]varchar [ (n) ]variable-length character stringString
cidrIPv4 or IPv6 network addressImplicit
circlecircle on a planeImplicit
datecalendar date (year, month, day)Date
double precisionfloat8double precision floating-point number (8 bytes)Float or String (flag)
inetIPv4 or IPv6 host addressImplicit
integerint, int4signed four-byte integerInt
interval [ fields ][ (p) ]time spanImplicit
jsontextual JSON dataJSON
jsonbbinary JSON data, decomposedJSONB
lineinfinite line on a planeImplicit
lsegline segment on a planeImplicit
ltreelabels of data stored in a hierarchical tree-like structureImplicit
geometryPostGIS Geometry typeGeometry
geographyPostGIS Geography typeGeography
macaddrMAC (Media Access Control) addressImplicit
macaddr8MAC (Media Access Control) address (EUI-64 format)Implicit
moneycurrency amountImplicit
numeric [ (p, s) ]decimal [ (p, s) ]exact numeric of selectable precisionNumeric or String (flag)
pathgeometric path on a planeImplicit
pg_lsnPostgreSQL Log Sequence NumberImplicit
pointgeometric point on a planeImplicit
polygonclosed geometric path on a planeImplicit
realfloat4single precision floating-point number (4 bytes)Float
smallintint2signed two-byte integerInt
smallserialserial2autoincrementing two-byte integerInt
serialserial4autoincrementing four-byte integerInt
textvariable-length character stringString
time [ (p) ][ without time zone ]time of day (no time zone)Implicit
time [ (p) ] with time zonetimetztime of day, including time zoneTimetz
timestamp [ (p) ][ without time zone ]date and time (no time zone)Implicit
timestamp [ (p) ] with time zonetimestamptzdate and time, including time zoneTimestamptz
tsquerytext search queryImplicit
tsvectortext search documentImplicit
txid_snapshotuser-level transaction ID snapshotImplicit
uuiduniversally unique identifierImplicit
xmlXML dataImplicit

Int

GraphQL default scalar with name Int.

E.g.

objects: [
{
int_col: 27
}
]

Float

GraphQL custom scalar type with name float8.

E.g.

objects: [
{
float_col: 0.8
}
]
Note

To avoid loss of data when retrieving IEEE 754 style data from the database, please refer to the GraphQL Engine server config reference for instructions on setting the extra_float_digits parameter, which has a bad default value in PostgreSQL 11 and older.

Numeric

GraphQL custom scalar type with name numeric.

E.g.

objects: [
{
numeric_col: 0.00000008
}
]

Bool

GraphQL default Scalar with name Boolean. The Boolean scalar type represents true or false.

E.g.

objects: [
{
is_published: true
}
]

Char

GraphQL custom scalar with name character. It is a String with single character.

E.g.

objects: [
{
char_column: "a"
}
]

String

GraphQL default scalar with name String. The String scalar type represents textual data, represented as UTF-8 character sequences. The String type is most often used by GraphQL to represent free-form human-readable text.

E.g.

objects: [
{
name: "Raven"
}
]

Date

GraphQL custom scalar with name date. Date (no time of day). Allowed values are yyyy-mm-dd.

E.g.

objects: [
{
date: "1996-03-15"
}
]

Time with time zone

GraphQL custom scalar type with name timetz. Time of day only, with time zone. Allowed values should be of ISO8601 format (e.g. 17:30:15Z, 17:30:15+05:30, 17:30:15.234890+05:30).

E.g.

objects: [
{
time: "17:30:15+05:30"
}
]

Timestamp with time zone

GraphQL custom scalar type with name timestamptz. Both date and time, with time zone. Allowed values should be of ISO8601 format (e.g. 2016-07-20T17:30:15Z, 2016-07-20T17:30:15+05:30, 2016-07-20T17:30:15.234890+05:30).

E.g.

objects: [
{
timestamptz_col: "2016-07-20T17:30:15+05:30"
}
]

JSON

GraphQL custom scalar type with name json. It is a stringified json value.

E.g.

objects: [
{
json_col: "{ \"name\": \"raven\" }"
}
]

JSONB

GraphQL custom scalar type with name jsonb. Value should be given through a variable of type jsonb.

E.g.

mutation insert_test($value: jsonb) {
insert_test(objects: [{ jsonb_col: $value }]) {
affected_rows
returning {
jsonb_col
}
}
}

variables:

{
"value": {
"name": "raven"
}
}

Geometry

GraphQL custom scalar type geometry is generated for a GEOMETRY column on a PostGIS enabled Postgres instance. Value should be given as GeoJSON.

E.g.

mutation insertGeometry($point: geometry!) {
insert_test(objects: [{ geometry_col: $point }]) {
affected_rows
returning {
geometry_col
}
}
}

variables:

{
"point": {
"type": "Point",
"coordinates": [0, 0]
}
}

Geography

GraphQL custom scalar type geography is generated for a GEOGRAPHY column on a PostGIS enabled Postgres instance. Value should be given as GeoJSON.

E.g.

mutation insertGeography($point: geography!) {
insert_test(objects: [{ geography_col: $point }]) {
affected_rows
returning {
geography_col
}
}
}

variables:

{
"point": {
"type": "Point",
"coordinates": [0, 0]
}
}

Implicitly supported types

All Implicit types in the above table are implicitly supported by the GraphQL engine. You have to provide the value as a String.

E.g. For time without time zone type

In ISO 8601 format

objects: [
{
time_col: "04:05:06.789"
}
]

E.g. For macaddr type

objects: [
{
macaddr_col: "08:00:2b:01:02:03"
}
]
Note

You can learn more about PostgreSQL data types here.