cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Stored procedure

suvi
Node Link

I have a simple doubt. 

Can't we write stored procedure in cypher itself and use it like other SQL databases? 

Is using Java is the only option we have?? 

10 REPLIES 10

Henrique
Node Link

Yeah , Using java is the only option so far.

Here you will find a good instruction on how to do that easily
https://neo4j.com/developer-blog/lets-write-a-stored-procedure-in-neo4j-part-i/

Hi @suvi 

This document is also helpful.
You can create your procedure by Cypher with APOC.
apoc.custom.asProcedure
https://neo4j.com/labs/apoc/4.4/overview/apoc.custom/apoc.custom.asProcedure/

I'm seeing a version mismatch when I attempt this.

The most recent of the jar that contains apoc.custom.asProcedure is 

apoc-4.4.0.5-all.jar. I'm running neo4j enterprise v4.4.6.

When I attempt to start neo4j (v4.4.6) with apoc-4.4.0.5-all.jar installed, I get the following complaint:
 

 

2022-06-11 18:32:25.708+0000 WARN  [neo4j/cf363efa] The apoc version (4.4.0.5) and the Neo4j DBMS versions [4.4.6] are incompatible. 
See the compatibility matrix in https://neo4j.com/labs/apoc/4.4/installation/ to see the correct version


It appears to me that I need to revert the version of Neo4J that I'm running all the way back to v4.4.0 in order to use anything in apoc.custom.

 

 
I'm not ready to take that drastic step.

Hi @tms !

2 things:

1. You may like to use https://neo4j.com/labs/apoc/4.2/overview/apoc.custom/apoc.custom.declareProcedure/ instead.

2. It's a incorrect warning that will be solved soon. If you are planning on use this custom procedures you may like to use APOC 4.4.0.3 (Compatible with 4.4.6)

Oh, y’all wanted a twist, ey?

The only plugin I have for APOC-4.4.0.3 is "apoc-4.4.0.3-core.jar". This is the "core" plugin, and does not include any apoc.custom methods. So far as I know, there is no "apoc-4.4.0.3-full.jar".

I'm under the perhaps incorrect impression that the "full" jar for 4.2 that you reference in your documentation URL is incompatible with neo4j enterprise v4.4.6.

So far as I know, this apoc.custom behavior is not currently available for neo4j enterprise 4.4.6.

@tms ,

2 things.

1. There's a full version of 4.4.0.3 here https://github.com/neo4j-contrib/neo4j-apoc-procedures/releases

2. Also there, you can find the fresh out the oven 4.4.0.6 

Oh, y’all wanted a twist, ey?

Hi @suvi 

I checked with the same version.

Neo4j Enterprise 4.4.6
APOC 4.4.0.6 (Good for 4.4.6 now)

スクリーンショット 2022-06-14 5.42.51.png

And I created the procedure.

https://neo4j.com/labs/apoc/4.4/overview/apoc.custom/apoc.custom.asProcedure/#usage-apoc.custom.asPr...

CALL apoc.custom.asProcedure(
  'powers',
  'UNWIND range(0, $power) AS power
   RETURN $input ^ power AS answer',
  'read',
  [['answer', 'long']],
  [['input','long'],  ['power', 'long']]
);

 

CALL custom.powers(9, 3);

 The result is here.
It works!!
スクリーンショット 2022-06-14 5.52.50.png

suvi
Node Link

Thanks @koji for that. I think this will work.
And also thanks to @Henrique for that article.
But now I wonder When should we use the Java implementation over the apoc custom procedure. Coz I feel former one is bit longer process. But I am sure there should be some advantage with the longer process.
would love to know what it is.

Hi @suvi!

Consider APOC as wrapper of your eventual implementation. At the end, it's a Java implementation on his own. In your use case, if the logic you want to wrap can be transform into Cypher predicates, you will be fine with APOC.

Some other cases may require a complex logic. In those scenarios you may need an implementation of your own. Learning how to do so will do no harm 😏

Oh, y’all wanted a twist, ey?

Thanks @bennu_neo .