Neo4j 4.2.5 MERGE doesn't work or it's behaviour has changed?

Hello there

Is it me or the behaviour of MERGE has changed in Neo4j 4.2.5

I think it's because I'm using the SET i = data operator which replace everything.
But in the context of ON CREATE WITH a MERGE clause it should keep the property defined in the merge?

The last MERGE clause in this query doesn't actually add the id property to the Impression node when creating it. Therefore, if I run the query again I have duplicates spawning for execution of the query.

CALL apoc.load.csv('gs://attribution_audit_client_015/csv/bds_pm_media_daily.csv?authenticationType=PRIVATE_KEY',{
{Date:{name:'date'}, Impressions:{name:'quantity', type:'int'}, Cost_USD:{name:'cost', type:'float'}, Clicks:{name:'clicks', type:'int'},Campaign_ID:{name:'campaign_id', type:'int'},Keyword_ID:{name:'keyword_id', type:'int'}}}
) YIELD map
WITH + '-' + toString(map.keyword_id) AS id, {quantity:map.quantity, clicks:map.clicks, cost:map.cost,} AS data, {name:map.campaign, id:map.campaign_id} AS campaign, {name:map.keyword, id:map.keyword_id} AS keyword

MERGE (i:Impression {id:id})
ON CREATE SET i = data

Fixed by using the += operator.

But still, does the = operator should behaves differently in the context of ON CREATE WITH MERGE?

The = operator, when used in any kind of SET operation to a node (SET node = map ), replaces all of its properties with the contents of the map, essentially removing all existing properties first.

As you found, += will add to the existing properties (replacing where there is a property in the map that also exists on the node), and any other properties not being overwritten will remain.

1 Like

I felt idiot when I figure it out :blush: