SQL - CREATE VERTEX
Creates a new vertex in the database.
The Vertex and Edge are the main components of a Graph database. ArcadeDB supports polymorphism on vertices.
Syntax
CREATE VERTEX [<type>] [BUCKET <bucket>]
[SET <field> = <expression>[,]*]|
[CONTENT {<JSON>}|[{<JSON>}[,]*]]
-
<type>Defines the type to which the vertex belongs. -
<bucket>Defines the bucket in which it stores the vertex. -
<field>Defines the field you want to set. -
<expression>Defines the express to set for the field.
| When using a distributed database, you can create vertices through two steps (creation and update). Doing so can break constraints defined at the type-level for vertices. To avoid these issues, disable constraints in the vertex type. |
Examples
-
Create a new vertex type, then create a vertex in that type:
ArcadeDB> CREATE VERTEX TYPE V1 ArcadeDB> CREATE VERTEX V1
-
Create a new vertex within a particular bucket:
ArcadeDB> CREATE VERTEX V1 BUCKET recent
-
Create a new vertex, defining its properties:
ArcadeDB> CREATE VERTEX SET brand = 'fiat'
-
Create a new vertex of the type
V1, defining its properties:
ArcadeDB> CREATE VERTEX V1 SET brand = 'fiat', name = 'wow'
-
Create a vertex using JSON content:
ArcadeDB> CREATE VERTEX Employee CONTENT { "name" : "Jay", "surname" : "Miner" }
-
Create multiple vertices using JSON content:
ArcadeDB> CREATE VERTEX Employee CONTENT [{"name" : "Jay", "surname" : "Miner"},
{"name": "Frank", "surname": "Hermier"},{"name": "Emily", "surname": "Sout"}]
Idempotent vertex creation (upsert)
CREATE VERTEX does not have an UPSERT clause. To create a vertex only if it does not already exist, or update it otherwise, use the UPDATE … UPSERT command against the vertex type. When the target type is a vertex type, UPSERT creates a real vertex (not a plain document), so it can be used as the endpoint of an edge right away.
The lookup must be backed by a UNIQUE index on the property used in the WHERE clause; this is what makes the operation atomic under concurrent writers.
ArcadeDB> CREATE VERTEX TYPE Person ArcadeDB> CREATE PROPERTY Person.email STRING ArcadeDB> CREATE INDEX ON Person (email) UNIQUE ArcadeDB> UPDATE Person SET name = 'Luca', email = '[email protected]' UPSERT WHERE email = '[email protected]'
Re-running the same UPDATE … UPSERT updates the existing vertex instead of creating a duplicate. See UPDATE for the full syntax and the upsert limitations.
For more information, see:
-
UPDATE(UPSERTclause)