apoc.refactor.normalizeAsBooleanProcedure
Syntax |
|
||
Description |
Refactors the given property to a |
||
Input arguments |
Name |
Type |
Description |
|
|
The node or relationship whose properties will be normalized to booleans. |
|
|
|
The name of the property key to normalize. |
|
|
|
The possible representations of true values. |
|
|
|
The possible representations of false values. |
|
Usage Examples
The examples in this section are based on the following sample graph:
CREATE (:Person {prop: 'Y', name:'A'}),
(:Person {prop: 'Yes', name:'B'}),
(:Person {prop: 'NO', name:'C'}),
(:Person {prop: 'X', name:'D'}),
(:Person {prop: true, name:'E'}),
(:Person {prop: false, name:'F'});
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. This includes BOOLEAN values as well.
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.name AS name, n.prop AS prop;
| name | prop |
|---|---|
"A" |
true |
"B" |
true |
"C" |
false |
"D" |
null |
"E" |
null |
"F" |
null |
If you want to keep BOOLEAN values as they are, include them in the parameters trueValues and falseValues:
MATCH (n) CALL apoc.refactor.normalizeAsBoolean(n,'prop',['Y','Yes', true],['NO', false]) WITH n ORDER BY n.id RETURN n.name AS name, n.prop AS prop;
| name | prop |
|---|---|
"A" |
true |
"B" |
true |
"C" |
false |
"D" |
null |
"E" |
true |
"F" |
false |