SurrealDB Docs Logo

Enter a search query

.insert()

Inserts one or multiple records in the database.

Method Syntax
db.insert(thing, data)

Arguments

ArgumentsDescription
thing required

The table name to insert to.

data required

Either a single document/record or an array of documents/records to insert

Example usage

# Insert a single record db.insert('person', { "name": 'Tobie', "settings": { "active": True, "marketing": True, }, }) # Insert multiple records db.insert('person', [ { "name": 'Tobie', "settings": { "active": True, "marketing": True, }, }, { "name": 'Jaime', "settings": { "active": True, "marketing": True, }, }, ])

Translated query

This function will run the following query in the database.

INSERT INTO $thing $data;

You can insert relations using the insert_relation() method.