API Reference - Supported PostgreSQL Types¶
Table of contents
Introduction¶
List of PostgreSQL types supported by the Hasura GraphQL engine with their equivalent Hasura types:
Name | Aliases | Description | Hasura Type |
---|---|---|---|
bigint | int8 | signed eight-byte integer | String |
bigserial | serial8 | autoincrementing eight-byte integer | String |
bit [ (n) ] | fixed-length bit string | Implicit | |
bit varying [ (n) ] | varbit [ (n) ] | variable-length bit string | Implicit |
boolean | bool | logical Boolean (true/false) | Bool |
box | rectangular box on a plane | Implicit | |
bytea | binary data (“byte array”) | Implicit | |
character [ (n) ] | char [ (n) ] | fixed-length character string | Char |
character varying [ (n) ] | varchar [ (n) ] | variable-length character string | String |
cidr | IPv4 or IPv6 network address | Implicit | |
circle | circle on a plane | Implicit | |
date | calendar date (year, month, day) | Date | |
double precision | float8 | double precision floating-point number (8 bytes) | Float |
inet | IPv4 or IPv6 host address | Implicit | |
integer | int, int4 | signed four-byte integer | Int |
interval [ fields ] [ (p) ] | time span | Implicit | |
json | textual JSON data | JSON | |
jsonb | binary JSON data, decomposed | JSONB | |
line | infinite line on a plane | Implicit | |
lseg | line segment on a plane | Implicit | |
geometry | PostGIS Geometry type | Geometry | |
geography | PostGIS Geography type | Geography | |
macaddr | MAC (Media Access Control) address | Implicit | |
macaddr8 | MAC (Media Access Control) address (EUI-64 format) | Implicit | |
money | currency amount | Implicit | |
numeric [ (p, s) ] | decimal [ (p, s) ] | exact numeric of selectable precision | Numeric |
path | geometric path on a plane | Implicit | |
pg_lsn | PostgreSQL Log Sequence Number | Implicit | |
point | geometric point on a plane | Implicit | |
polygon | closed geometric path on a plane | Implicit | |
real | float4 | single precision floating-point number (4 bytes) | Float |
smallint | int2 | signed two-byte integer | Int |
smallserial | serial2 | autoincrementing two-byte integer | Int |
serial | serial4 | autoincrementing four-byte integer | Int |
text | variable-length character string | String | |
time [ (p) ] [ without time zone ] | time of day (no time zone) | Implicit | |
time [ (p) ] with time zone | timetz | time of day, including time zone | Timetz |
timestamp [ (p) ] [ without time zone ] | date and time (no time zone) | Implicit | |
timestamp [ (p) ] with time zone | timestamptz | date and time, including time zone | Timestamptz |
tsquery | text search query | Implicit | |
tsvector | text search document | Implicit | |
txid_snapshot | user-level transaction ID snapshot | Implicit | |
uuid | universally unique identifier | Implicit | |
xml | XML data | Implicit |
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 flags 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.