How to update properties of relation with condition on date property?

My relation table is as follow

Initial insertion Value at adding
origin_node node_destination date_b city
1 2 2016-10-23 Montréal

At the first time, just insert the relation with date property: no problem

At th second time, it's not possible to set another property with the condition on a property date

My adding property is like

Thanks in advance

I am sorry. I don't understand your issue. The code with the circle is highlighting a MATCH clause, so the relationship property will not be set. What are you trying to accomplish?

I want to search the relationship with condition on date to update the other property

The syntax looks correct for restricting to relationships that have the property value.

What is the result you are getting and what did you expect?

I would hope that the other property (city) is updated but nothing happens because the condition on the date does not work even if I format the date field with datetime. But if I remove the condition on the date everything works fine.

I don’t see a need for the apoc.cypher.run procedure, since you have not built the cypher query dynamically. I suggest replacing it with your match statement. You also have two return statements in the match statement. I have not seen that. Maybe this is causing ‘r’ to be null. Remove “return orig,dest” since you are not using those variables anyways, leaving “return r”.

Thanks, 'return orig, dest' is a mistake. please it's possible to have an example to " replacing match statement"?

I want to remember that the problem concerns the condition of date property, if i remove this the relation will be inserted correctly

Can you paste the original code? I will refactor it.

Prepared BD neo4j
create (:Person{id:"1"})-[:FOLLOW{date_b:Date("2023-10-13")}]->(:Person{id:"2"})

My request

call apoc.periodic.iterate(
'
call apoc.load.jdbc ("jdbc: oracle: thin: login/pass@sfpclbd88.prod.mrq:1521/localhost",
select origin_node, destination_node, date_b,city from table_relation
) yield row return row
',
'
call apoc.cypher.run(" match (: Person{id: row.origin_node})-[r: FOLLOW { date_b: Date(row.date_b)}]->
(: Person {id: row.destination_node}) return r", {row:row}) yield value
with value, row
call apoc.create.setRelProperty (value.r, "City", row.city)
yield rel return rel
{batchSize:1000, parallel:false})

Try this:

call apoc.periodic.iterate(
'
    call apoc.load.jdbc (
        "jdbc:oracle:thin:login/pass@sfpclbd88.prod.mrq:1521/localhost",
        "select origin_node, destination_node, date_b, city from table_relation"
    ) yield row return row
',
'
    match (o:Person{id:row.origin_node})
    match (d:Person{id:row.destination_node})
    match (o)-[r:FOLLOW{date_b:Date(row.date_b)}]->(d)
    call apoc.create.setRelProperty(r, "City", row.city) yield rel 
    return rel
', 
{batchSize:1000, parallel:false})

The "return" is needed because the query complains that the query can't terminate with a call subquery. You can change it to return 1 instead of rel.

1 Like

Thanks very much, it works.
N.B : don't forget to put the property in UPPERCASE

1 Like