Authors: Henrik Nyman henrik.nyman@neotechnology.com, Mats Rydberg mats@neotechnology.com
Abstract
This CIP describes how type coercions work in Cypher.
Table of Contents
It is useful for a user to know what kinds of coercions Cypher will perform, and what explicit casting they will need to do themselves.
The three type coercions are as follows:
-
LIST OF T
toBOOLEAN
-
LIST OF NUMBER
toLIST OF FLOAT
-
INTEGER
toFLOAT
The following queries exemplify type coercions.
Check if a list is empty, and if it is not, return the first element:
WITH [] AS coll
WHERE coll // coerced to a boolean
RETURN coll[0]
Return the size of a non-empty list:
WITH [1, 2, 3.5] AS coll
WHERE coll // coerced to a boolean
RETURN size(coll)
Calculate the cosine of a value:
WITH 1 AS int
RETURN cos(int) // coerced to a float
Store a list of numbers as a node property:
WITH [1, 1.0] AS list
CREATE ({l: list})) // coerced to a list of floats
Extract a specific element from a list by index:
WITH ['a', 'b', 'c'] AS list, 1.5 AS float
RETURN list[toInteger(float)] // explicit conversion required
PostgreSQL states three principles that guide their handling of type conversions. SQL Server and Oracle DB have larger type sets and define many implicit conversions between the types.