apoc.custom.asFunction
Procedure APOC Full Deprecated
apoc.custom.asFunction(name, statement, outputs, inputs, forceSingle, description) - register a custom cypher function
Signature
apoc.custom.asFunction(name :: STRING?, statement :: STRING?, outputs = :: STRING?, inputs = null :: LIST? OF LIST? OF STRING?, forceSingle = false :: BOOLEAN?, description = :: STRING?) :: VOID
Input parameters
Name | Type | Default |
---|---|---|
name |
STRING? |
null |
statement |
STRING? |
null |
outputs |
STRING? |
|
inputs |
LIST? OF LIST? OF STRING? |
null |
forceSingle |
BOOLEAN? |
false |
description |
STRING? |
Usage Examples
Please note that apoc.custom.asFunction
and apoc.custom.asProcedure
are deprecated in favor of apoc.custom.declareFunction
and apoc.custom.declareProcedure
.
See here for more info.
This is the list of input parameters, name
and statement
are mandatory fields:
name | default | description |
---|---|---|
|
|
dot-separated name, will be prefixed with |
|
|
cypher statement to run, can use $parameters |
|
|
Output type for single output, if the type is a list, then all rows will be collected, otherwise just the first row. Only single column results are allowed.
If your single row result is a list you can force a single row by setting the last parameter to |
|
|
Pairs or triples of name-type-default, to be used as input parameters. The default just takes an optional map, otherwise they will become proper parameters in order |
|
|
If set to true, the statement is treated as single row even with the list result type, then your statement has to return a list. |
|
|
A general description about the business rules implemented into the function |
Given statement will be registered as a statement, the results into a single value. If the given output type is a list, results will be collected into a list, otherwise the first row will be used. The statement needs to return a single column, otherwise an error is thrown.
The type names can be the same as apoc.custom.declare*
analogues.
Here is a simple example:
CALL apoc.custom.asFunction('answer','RETURN 42')
We can create the function custom.double
, that doubles the provided value, by running the following function:
CALL apoc.custom.asFunction(
'double',
'RETURN $input*2 as answer',
'long',
[['input','number']]
);
We can use this function, as shown in the query below:
RETURN custom.double(12) AS value;
value |
---|
24 |