0

Based on previous cybersam answer on the following link How to create unique constraint involving multiple properties in Neo4J

I need to apply his answer on my use case.

CREATE CONSTRAINT ON ( city:City ) ASSERT city.cityName IS UNIQUE

CREATE CONSTRAINT ON ( city:City ) ASSERT city.regionIdentifier IS UNIQUE

That means combine these both properties as group (cityName,regionIdentifier)

CITY PROPERTIES

<id>:3
cityName:BLANKEMPTYVIDE1009
description:BLANKEMPTYVIDE1009
id:3
identifier:3374991009
region:BLANKEMPTYVIDE1009
regionIdentifier:100
zip:3374991009

The same thing should apply by combining these three properties on (sectorname,description,regionIdentifier)

CREATE CONSTRAINT ON ( sector:Sector ) ASSERT sector.description IS UNIQUE

CREATE CONSTRAINT ON ( sector:Sector ) ASSERT sector.regionIdentifier IS UNIQUE

CREATE CONSTRAINT ON ( sector:Sector ) ASSERT sector.sectorName IS UNIQUE

SECTOR PROPERTIES

<id>:2
city:BLANKEMPTYVIDE1002
cityIdentifier:3374991002
description:BLANKEMPTYVIDE1002_BLANKEMPTYVIDE1002
id:2
identifier:3374991002
region:BLANKEMPTYVIDE1002
regionIdentifier:100
sectorName:BLANKEMPTYVIDE1002_BLANKEMPTYVIDE1002
zip:BLANKEMPTYVIDE1002_BLANKEMPTYVIDE1002
Schwertfisch
  • 133
  • 3
  • 16
  • 2
    Note that if you have the ability to use Neo4j Enterprise (either via commercial license, or if you meet [other criteria for Enterprise version usage](https://neo4j.com/licensing/), you can take advantage of [Node Key constraints](https://neo4j.com/docs/developer-manual/current/cypher/schema/constraints/#query-constraint-node-key), which should fulfill your need. – InverseFalcon Jun 03 '18 at 07:07
  • Thank you InverseFalcon for your response but unfortunately I have community edition and my use case is not for enterprise version usage. – Schwertfisch Jun 03 '18 at 20:26
  • 1
    I agree with @InverseFalcon ... but if that's not an option, you could create an extra property that contains a concat of the relevant properties (or a hash of the concat of the relevant properties) and put a constraint on that. – Tom Geudens Jun 04 '18 at 12:27
  • Pure concatenation is not guaranteed to create unique values (e.g., 'a'+'bc' and 'ab'+'c' both become 'abc'). One workaround is to separate the individual values with, say, a '|' character ('a|bc' versus 'ab|c'). – cybersam Jun 04 '18 at 20:26
  • Thanks for your help cyberSam I'll apply your advice could you transfer your comment to an answer so I could accept it Thank you. – Schwertfisch Jun 04 '18 at 21:53
  • Tom Geudens Thank you very much I see That I had to add an extra property but as cyberSam added I had to put an relevant character to separate both cases. Thank you very much. – Schwertfisch Jun 04 '18 at 21:56

0 Answers0