API
Python
Description
Summary
Allow node tables to declare a primary key composed of multiple columns, e.g. PRIMARY KEY (col_a, col_b). The tuple of values is the unique identifier, and the hash index, MERGE, and COPY FROM for relationships operate against the tuple rather than a single column.
Motivation
There are several common modeling patterns where the natural identity of an entity is a tuple rather than a single value:
- Join / association entities:
Enrollment(student_id, course_id), OrderItem(order_id, line_num), Permission(role_id, resource_id).
- Multi-tenant data:
User(tenant_id, user_id), Document(tenant_id, doc_id).
- Hierarchical or scoped IDs:
Chapter(book_id, chapter_num), Comment(post_id, comment_id), LineItem(invoice_id, position).
- Time-keyed records:
DailyMetric(entity_id, date), SensorReading(device_id, timestamp).
- Geographic or hierarchical natural keys:
(country_code, postal_code), (state, county, tract).
For all of these, the composite is the identity, and expressing it directly in the schema keeps domain meaning where it belongs.
Proposed semantics
CREATE NODE TABLE OrderItem (
order_id INT64,
line_num INT64,
quantity INT64,
price DOUBLE,
PRIMARY KEY (order_id, line_num)
);
Behavior:
- The tuple
(order_id, line_num) is the unique identifier; inserting two nodes with the same tuple violates the PK constraint.
- Point lookups via
MATCH (o:OrderItem {order_id: 42, line_num: 7}) use the PK index.
MERGE (o:OrderItem {order_id: 42, line_num: 7}) ON CREATE SET ... matches against the composite for upsert semantics.
COPY FROM for relationships accepts multiple FROM-key columns in the source file, matched positionally to the PK columns.
API
Python
Description
Summary
Allow node tables to declare a primary key composed of multiple columns, e.g.
PRIMARY KEY (col_a, col_b). The tuple of values is the unique identifier, and the hash index,MERGE, andCOPY FROMfor relationships operate against the tuple rather than a single column.Motivation
There are several common modeling patterns where the natural identity of an entity is a tuple rather than a single value:
Enrollment(student_id, course_id),OrderItem(order_id, line_num),Permission(role_id, resource_id).User(tenant_id, user_id),Document(tenant_id, doc_id).Chapter(book_id, chapter_num),Comment(post_id, comment_id),LineItem(invoice_id, position).DailyMetric(entity_id, date),SensorReading(device_id, timestamp).(country_code, postal_code),(state, county, tract).For all of these, the composite is the identity, and expressing it directly in the schema keeps domain meaning where it belongs.
Proposed semantics
Behavior:
(order_id, line_num)is the unique identifier; inserting two nodes with the same tuple violates the PK constraint.MATCH (o:OrderItem {order_id: 42, line_num: 7})use the PK index.MERGE (o:OrderItem {order_id: 42, line_num: 7}) ON CREATE SET ...matches against the composite for upsert semantics.COPY FROMfor relationships accepts multiple FROM-key columns in the source file, matched positionally to the PK columns.