cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Create constraint on a property set by me and the index set by neo4j.

I would like a node to be unique based on two constraints:

1. A property set by me

2. The index as set by neo4j at the creation of the node

This is what I've tried so far:

CREATE CONSTRAINT transaction_constraint IF NOT EXISTS 
FOR (tx: Transaction) 
REQUIRE(tx.`Transaction Hash`, id(tx)) IS  UNIQUE

but this is the error I get:

py2neo.errors.ClientError: [Statement.SyntaxError] Invalid input '(': expected "." (line 4, column 70 (offset: 221))
"REQUIRE(tx.`Transaction Hash`, id(tx)) IS  UNIQUE"
                                  ^

I would like to avoid having an extra id that I manually increment to keep things neat if possible.

1 ACCEPTED SOLUTION

You can't index the internal node id. Anyways the id() of a node is always present and unique across nodes, so what you are trying to do will always be unique regardless of 'Transaction Hash'. You can use the id() as an identifier if you want. Keep in mind that the values are reused. 

View solution in original post

2 REPLIES 2

You can't index the internal node id. Anyways the id() of a node is always present and unique across nodes, so what you are trying to do will always be unique regardless of 'Transaction Hash'. You can use the id() as an identifier if you want. Keep in mind that the values are reused. 

@glilienfield Thank you for the answer! I was trying to find a way to distinguish coinbase transactions as they all have the same hash. Ultimately, block hash along with transaction hash were used as constraints.