Skip to content
lvca edited this page Dec 14, 2012 · 1 revision

SQL Insert

The SQL Insert command creates a new record into the database. Records can be schema-less.

Syntax

    INSERT INTO <Class>|cluster:<cluster>|index:<index> [<cluster>](cluster) [VALUES (<expression>[,]((<field>[,]*))*)]|[<field> = <expression>[,](SET)*]

Examples

Insert a new record with name 'Jay' and surname 'Miner'

    insert into Profile (name, surname) values ('Jay', 'Miner' )
    insert into Profile SET name = 'Jay', surname = 'Miner'

Insert a new record of type Profile but in a different cluster than the default one

    insert into Profile cluster profile_recent (name, surname) values ('Jay', 'Miner' )

Insert several records at the same time

    insert into Profile(name,surname) VALUES ('Jay','Miner'),('Frank','Hermier),('Emily','Saut')

Insert a new record adding a relationship

    insert into Employee (name, boss) values ('jack', #11:99 )
    insert into Employee SET name = 'jack', boss = #11:99

Insert a new record adding a collection of relationship

    insert into Profile (name, friends) values ('Luca', [#10:3, #10:4] )
    insert into Profile SET name = 'Luca', friends =  [#10:3, #10:4]

Sub-selects

    insert into Diver SET name = 'Luca', buddy = (select from Diver where name = 'Marko')

Sub-inserts

    insert into Diver SET name = 'Luca', buddy = (insert into Diver name = 'Marko')

Insert in a different cluster

This inserts a new document in the cluster 'asiaemployee':

    insert into cluster:asiaemployee (name) values ('Mattew')

But note that the document will have no class assigned. To create a document of a certain class but in a different cluster than the default one use:

    insert into cluster:asiaemployee (@class, content) values('employee', 'Mattew')

That will insert the document of type 'employee' in the cluster 'asiaemployee'.

Insert a new record adding an embedded document

    insert into Profile (name, address) values ('Luca', { "@type" : "d", "street" : "Melrose Avenue", "@version" : 0 } )

To know more about other SQL commands look at SQL commands.

Clone this wiki locally