apoc.custom.declareProcedure

Procedure APOC Full Deprecated

apoc.custom.declareProcedure(signature, statement, mode, description) - register a custom cypher procedure

Signature

apoc.custom.declareProcedure(signature :: STRING?, statement :: STRING?, mode = read :: STRING?, description =  :: STRING?) :: VOID

This procedure is not intended to be used in a cluster environment, and may act unpredictably.

Input parameters

Name Type Default

signature

STRING?

null

statement

STRING?

null

mode

STRING?

read

description

STRING?

Usage Examples

Here is a simple example:

CALL apoc.custom.declareProcedure('answerInteger() :: (row::INT)', 'RETURN 42 as answer')

This registers the statement as procedure custom.answer that you then can call.

CALL custom.answerInteger
Table 1. Results
answer

42

Or you can also write in this way:

CALL apoc.custom.declareProcedure('answer() :: (row::MAP)', 'RETURN 42 as answer')

In this case the result is wrapped in a stream of maps called row. Therefore, you can do:

CALL custom.answer() YIELD row
RETURN row.answer
Table 2. Results
answer

42

which is equivalent to deprecated one:

CALL apoc.custom.asProcedure('answer','RETURN 42 as answer')

We can create the function custom.powers that returns a stream of the powers of the first parameter, up to and including the power provided by the second parameter:

CALL apoc.custom.declareProcedure(
  'powers(input::INT, power::INT) :: (answer::INT)',
  'UNWIND range(0, $power) AS power
   RETURN $input ^ power AS answer'
);
Procedure, input and output names must have at least 2 characters.

We can use this function, to return 4°, 4¹, 4², and 4³, as shown in the query below:

call custom.powers(4,3);
Table 3. Results
answer

1.0

4.0

16.0

64.0

Furthermore, we can pass as the 3rd parameter a string to specify the procedure mode (default "WRITE"). It can be: - "READ" - if the procedure will only perform read operations against the graph - "WRITE" - if it may perform both read and write operations against the graph - "SCHEMA" - if it will perform operations against the schema - "DBMS" - if it will perform system operations - i.e. not against the graph

Moreover, we can pass a description parameter as the 4th parameter, which will be returned by the call apoc.custom.list and SHOW PROCEDURES.