6.9.1.1.2 Type Casting

Type casting is supported in PGQL with a SQL-style CAST (VALUE AS DATATYPE) syntax, for example CAST('25' AS INT), CAST (10 AS STRING), CAST ('2005-02-04' AS DATE), CAST(e.weight AS STRING). Supported casting operations are summarized in the following table. Y indicates that the conversion is supported, and N indicates that it is not supported. Casting operations on invalid values (for example, CAST('xyz' AS INT)) or unsupported conversions (for example, CAST (10 AS TIMESTAMP)) return NULL instead of raising a SQL exception.

Table 6-4 Type Casting Support in PGQL (From and To Types)

“to” type from STRING from INT from LONG from FLOAT from DOUBLE from BOOLEAN from DATE from TIMESTAMP from TIMESTAMP WITH TIMEZONE

to STRING

Y

Y

Y

Y

Y

Y

Y

Y

Y

to INT

Y

Y

Y

Y

Y

Y

N

N

N

to LONG

Y

Y

Y

Y

Y

Y

N

N

N

to FLOAT

Y

Y

Y

Y

Y

Y

N

N

N

to DOUBLE

Y

Y

Y

Y

Y

Y

N

N

N

to BOOLEAN

Y

Y

Y

Y

Y

Y

N

N

N

to DATE

Y

N

N

N

N

N

Y

Y

Y

to TIMESTAMP

Y

N

N

N

N

N

Y

Y

Y

to TIMESTAMP WITH TIMEZONE

Y

N

N

N

N

N

Y

Y

Y

An example query that uses type casting is:

SELECT e.name, CAST (e.birthDate AS STRING) AS dob
FROM MATCH (e)
WHERE e.birthDate < CAST ('1980-01-01' AS DATE)