merge with paths tries to create the whole path, you need to have bound
nodes first if you only want to create the rel (if it is missing)

MATCH (root:Company { name: 'AdverCar' })
MATCH (country:Country{ name : 'UK'})
MERGE (root)-[:COUNTRY]->(country)
RETURN country

or


MATCH (root:Company { name: 'AdverCar' })
MERGE (country:Country{ name : 'UK'})
MERGE (root)-[:COUNTRY]->(country)
RETURN country



On Thu, Apr 24, 2014 at 12:10 AM, Gregory Rayzman <[email protected]>wrote:

> Running neo4j 2.0.2 on Windows 7.
>
>
> Have 2 entities: company and country, with unique constraint on names
>
> CREATE CONSTRAINT ON (a:Company) ASSERT a.name IS UNIQUE;
>
> CREATE CONSTRAINT ON (a:Country) ASSERT a.name IS UNIQUE;
>
>
> CREATE (a:Company{ name : 'AdverCar'}) RETURN a;
>
> create relationship
> MATCH (root:Company { name: 'AdverCar' })
> MERGE (root)-[:COUNTRY]->(country:Country{ name : 'USA'})
> RETURN country
> ;
>
> It is possible to rerun last statement multiple times without any errors.
> MATCH (root:Company { name: 'AdverCar' })
> MERGE (root)-[:COUNTRY]->(country:Country{ name : 'USA'})
> RETURN country
> ;
>
> and
> MERGE (a:Country{ name : 'USA'}) RETURN a;
> MERGE (a:Country{ name : 'CAN'}) RETURN a;
> works fine
>
>
>
> BUT creating country first and establishing relationship between company
> and country throws exception.
>
> MERGE (a:Country{ name : 'CAN'}) RETURN a;
>
>
> MATCH (root:Company { name: 'AdverCar' })
> MERGE (root)-[:COUNTRY]->(country:Country{ name : 'CAN'})
> RETURN country
> ;
> CypherExecutionException: Node 2176 already exists with label Country and
> property "name"=[CAN]
>
>
> CREATE (a:Country{ name : 'UK'}) RETURN a;
>
> MATCH (root:Company { name: 'AdverCar' })
> MERGE (root)-[:COUNTRY]->(country:Country{ name : 'UK'})
> RETURN country
> ;
> CypherExecutionException: Node 2177 already exists with label Country and
> property "name"=[UK]
>
>
> Thanks for any help you can provide.
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Neo4j" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to