How to pass parameter dat_maj to iterate procedure used in sql request?

Hello,
I would like to retrieve the date_maj parameter in a PARAM node and use it as a parameter in iterate.
THANKS

call apoc.cypher.run("MATCH (n: PARAM) return n.DAT_MAJ as DAT_MAJ",{}) yield value return value.DAT_MAJ as dat_maj 

call apoc.periodic.iterate (
             ' call apoc.load.jdbc
                    ($url,
                     "select distinct ORIGIN, TYPE_NOEUD_ORIGINE,  
                      DESTINATION, TYPE_NOEUD_DESTINATION, DAT_DEB
                      from TEST_RELATION
                      where DAT_DEB > to date (?, \'YYYY-MM-DD\')
                     ",
                      [dat_maj]
                    ) yield row
             ',
            ' call apoc.cypher.run(" match (orig:"+ row.TYPE_NOEUD_ORIGINE +"{ID:row.ORIGIN}),
                                      (dest:"+ row.TYPE_NOEUD_DESTINATION +"{ID:row.DESTINATION})  
                                       return orig, dest", {row: row}
                                    ) yield value return value
           ',
          {batchSize:1000, parallel: false, params: {url: $url, dat_maj: dat_maj}}

Just a note, you should not need the first usage of apoc.cypher.run, as you should be able to use match directly.

You pass the external values in a map passed as the “params” parameter in the apoc.periodic.iterate config parameter’s map. Looks like you did this part. You can reference it in the cypher statements passed to the apoc iterate method as $dat_maj.

Finally, it looks like there is missing syntax in your query.

thank, the main problem is how to pass the parameter to iterate procedure.

Something, I have the following error.

I've also modify th synthax of my request because the quotation marks have been forgotten.

Advance thanks

Are you using a ‘call’ without a ‘yield’ ?

Can you post the latest code with the proper syntax?”

Hi,
I just want to use a value (nameParam in follow example) like condition comming from an another cypher request.

like

Math (p:Param{ID:'1'}) return p.name as nameParam

call apoc.periodic.iterate('','',{params:{name:$nameParam}}

thanks advance!

What do you mean from a different cypher request? How are you chaining the result from the match to the apoc call if nit in the same cypher query? Are you using a driver?

In summary, I want to pass a value in iterate procedure that will be use in sql request.

For example, this block runs correctly in browser but no in cypher-shell. I just simplify the request.

This code block runs correctly in browser but no in cypher-shell.

:param [{val}] => {return 1 as val};
call apoc.periodic.iterate
( ' call apoc.load.jdbc ( $url, "select 1 as test from dual where 1=?",[$val]) yield row'
   ,
  'with row create (p:Test(ID:row.TEST)) '
,
{params:{url:$url,val:$val}}

)

N.B : the url is firstly defined in param like

 :param url => 'jdb:oracle:thin:user/pass@localhost:1521/localhost'

Thanks in advance

I don't understand this syntax:

:param [{val}] => {return 1 as val};

Do you get an error message back when executed in cypher-shell?

It's pleasure to me to explain this.
But, this syntax allows me to create a parameter from cypher request.
This corresponds to **:param val => 1**
In in my actually work, it's a big request, i just simplify it here.

Confer Query parameters - Neo4j Browser.

Of course, It works in browser but not in cypher-shell.

thanks

Damn, you read deep into the documentation. My kind of person. I recall reading that a while back, but never used it.

I tried that syntax in the browser and cypher-shell. It worked in browser and not cypher-shell. As such, I don't think it is supported in cypher-shell.

Are you trying to use a parameter, so you can set it and use it multiple times in the same session? Or, can we derive the parameter value in the same query as the apoc.periodic.iterate call?

1 Like

If you are trying to execute them both in the same query, then look at this example:

match (p:ParentNodeLabel)  
where id(p) = 25
with p.name as nameParam
call apoc.periodic.iterate(
    'match(n:ParentNodeLabel) return n',
    'set n.test = $name',
    {params:{name:nameParam}}
) yield total
return total

You can also use a call subquery:

call {
    match (p:ParentNodeLabel)  
    where id(p) = 25
    return p.name as nameParam
}
call apoc.periodic.iterate(
    'match(n:ParentNodeLabel) return n',
    'set n.test = $name',
    {params:{name:nameParam}}
) yield total
return total
1 Like

wow!!!!!

I wonder what do you eat? I am undoubtedly convinced that if I do not have a solution to a problem posed to you (here) it is because I posed it incorrectly.

Thank you very much

Please can you recommend a training course that I can do because so far my learning is independent.

Best regards

I used to eat a lot of neo4j documentation. I found it very useful as a learning tool. There are certain topics and tools that I have found very useful to know:

Understanding path patterns
aggregation and how the rows are grouped
list comprehension
map comprehension
call subqueries
using 'with' to derive new variables, aggregate data, and to pass values
list predicates
collect, exists, and count subqueries
unwind and how the data is merged to form the new rows

There are neo4j's graph Academy courses.

The cypher manual is very informative.

1 Like