Normalize As Boolean
The available procedure is described in the table below:
Qualified Name | Type | Release |
---|---|---|
apoc.refactor.normalizeAsBoolean
|
|
|
Example Usage
The example below will help us learn how to use this procedure.
The following creates a graph containing nodes with boolean properties representented in different formats:
CREATE (:Person {prop: 'Y', name:'A'}),
(:Person {prop: 'Yes', name:'B'}),
(:Person {prop: 'NO', name:'C'}),
(:Person {prop: 'X', name:'D'})
We want to transform some properties into a boolean, Y
, Yes
into true and the properties NO
into false.
The other properties that don’t match these possibilities will be set as null
.
The following normalizes all applicable boolean values for all nodes that have the
prop
property:MATCH (n)
CALL apoc.refactor.normalizeAsBoolean(n,'prop',['Y','Yes'],['NO'])
WITH n
ORDER BY n.id
RETURN n.prop AS prop
If we execute this query, we’ll see the following result: