Property Graph Databases
2024-11-22
Object databases: flexible, NoSQL
Relational databases: strict schema, SQL
RDF databases: flexible, RDF model
Confused? That’s ok!
Create graph (no schema):
Convert PG to Cypher with additional properties:
Result:
Node identifiers are not stable!
CREATE (:person {gender:"male", name:"Anakin"});
CREATE (:robot {color:["golden","silver"], name:"C3PO"});
CREATE (:person {gender:"male", name:"Luke"});
CREATE (:person {gender:"female", name:"Padmé"});
CREATE (:robot {name:"R2D2"});
MATCH (a {name:"Padmé"}), (b {name:"R2D2"}) CREATE (a)-[:owns {episode:1}]->(b);
MATCH (a {name:"Anakin"}), (b {name:"R2D2"}) CREATE (a)-[:owns {episode:2}]->(b);
MATCH (a {name:"Anakin"}), (b {name:"Luke"}) CREATE (a)-[:child {episode:3}]->(b);
MATCH (a {name:"Padmé"}), (b {name:"Luke"}) CREATE (a)-[:child {episode:3}]->(b);
MATCH (a {name:"Luke"}), (b {name:"R2D2"}) CREATE (a)-[:owns {episode:4}]->(b);
MATCH (a {name:"Luke"}), (b {name:"C3PO"}) CREATE (a)-[:owns {episode:4}]->(b);
Cypher | |
---|---|
nodes | (a :robot) , (a :robot :agent) |
edges | (a) -[:friend]-> (b) |
properties | {episode:4, color:["golden","silver"]} |
PG | |
---|---|
nodes | a :robot , a :robot :agent |
edges | a -> b :friend |
properties | episode:4 color:golden,silver |
There’s also a serialization in JSON!
INTEGER
FLOAT
(64 bit floating point)STRING
(Unicode string)BOOLEAN
LIST OF
any other data typeCreate and run container (without attached volume):
Visit http://localhost:7474
Select Get Started for Free at neo4j.com and “Start Free” from there to create an account (single sign on possible with an existing Google account)
Create a free database instance
Copy & save the password!
Wait a few minutes
Select “Query”
star-wars-example.cypherl
)agent
as wellmale
LOAD CSV
(no standard but pretty common)pgraph
Sorry, not investigated yet!
CREATE CONSTRAINT FOR (r:robot) REQUIRE r.name IS UNIQUE;
CREATE CONSTRAINT ON (r:robot) ASSERT r.name IS UNIQUE;
CREATE CONSTRAINT FOR (r:robot) REQUIRE r.name IS NOT NULL;
CREATE CONSTRAINT ON (r:robot) ASSERT exists (r.name);
CREATE INDEX robot_name FOR (r:robot) ON r.name
CREATE INDEX ON :robot(name);
Neo4J: No (explicit) schema, only constraints
CALL db.schema.visualization()
Kùzu:
Something like this (I could not verify)
CREATE GRAPH TYPE StarWars AS {
(:person { name::STRING NOT NULL, gender::STRING }),
(:robot { name::STRING NOT NULL, color:: LIST OF STRING }),
(:person)-[:owns]->(:robot)
}
Other syntax variants exist.
↑ Performant & Scalable
↓ Flexible