Permalink
Fetching contributors…
Cannot retrieve contributors at this time
82 lines (60 sloc) 1.88 KB

CIP2015-11-09 Type coercions

Authors: Henrik Nyman henrik.nyman@neotechnology.com, Mats Rydberg mats@neotechnology.com

Abstract

This CIP describes how type coercions work in Cypher.

1. Motivation

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.

2. Proposal

The three type coercions are as follows:

  • LIST OF T to BOOLEAN

  • LIST OF NUMBER to LIST OF FLOAT

  • INTEGER to FLOAT

2.1. Examples

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

2.2. Syntax

No syntax changes are proposed.

2.3. Semantics

There are no new semantics to consider.

3. What others do

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.