How to avoid duplicating setting same property in both create and match for merge

We are importing a lot of data from CSV files. Because we want to be able to both create new nodes and "fix" existing nodes (for any particular import). We've come up with the following "pattern".

// Find any name-matched DB Tables
WITH 'NAMING_MATCHING' AS arcBaseName
MATCH (ab:ArcBase {name:arcBaseName})
CALL apoc.cypher.doIt("
MATCH (o:DBTable)
MATCH (d:DBTable {name:o.name}) WHERE id(o)<id(d) // use id() to ensure only one bidirectional link and to stop self-reflection
MERGE (o)-[r:"+ arcBaseName +" {name:o.name+'-"+ab.name+"-'+d.name}]->(d)
ON CREATE
SET r.uuid=randomUUID(),
r.extendedCaption=o.name+'-"+ab.caption+"-'+d.name, r.caption='"+ab.caption+"',
r.originName=o.name, r.originUUID=o.uuid, r.destinationName=d.name, r.destinationUUID=d.uuid
ON MATCH
SET
r.extendedCaption=o.name+'-"+ab.caption+"-'+d.name, r.caption='"+ab.caption+"',
r.originName=o.name, r.originUUID=o.uuid, r.destinationName=d.name, r.destinationUUID=d.uuid
WITH r
RETURN COUNT(r) AS counter
", {}) yield value
RETURN value.counter
;

As you can see, we have ALMOST duplicated the setting of the same set of properties in BOTH the CREATE and MATCH clauses. Is there any way to say something like:

MATCH (d:DBTable {name:o.name}) WHERE id(o)<id(d) // use id() to ensure only one bidirectional link and to stop self-reflection
MERGE (o)-[r:"+ arcBaseName +" {name:o.name+'-"+ab.name+"-'+d.name}]->(d)
SET r.extendedCaption=o.name+'-"+ab.caption+"-'+d.name, r.caption='"+ab.caption+"',
r.originName=o.name, r.originUUID=o.uuid, r.destinationName=d.name, r.destinationUUID=d.uuid
ON CREATE
SET r.uuid=randomUUID()
r.originName=o.name, r.originUUID=o.uuid, r.destinationName=d.name, r.destinationUUID=d.uuid

i.e. set the main set regardless of CREATE or MATCH; only set the additional property on CREATE.

TIA,
Paolo

Yes, perform the 'set' after both 'on match set' and 'on create set', as those are associated with the merge. 'set' can be used with create, match, merge, and with.

Thanks, @glilienfield,

Looks like ON MATCH and ON CREATE clauses are both optional. So I'm going to interpret the syntax as
MERGE
ON CREATE stuff to be set for create only
ON MATCH stuff to be set for a match only
SET stuff to be set for both

If there's nothing to be set for that condition, leave the sub-clause out. Is that the correct way to interpret it?

Paolo

That is correct. Keep in mind that Set is its own clause. It can be with a create, match, merge, and with clauses. The ‘on match set’ and on create set‘ are specific to merge.