SurrealDB Docs Logo

Enter a search query

.insert_relation()

Inserts one or multiple relations in the database.

Method Syntax
db.insert_relation(table, data)

Arguments

ArgumentsDescription
table 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_relation('likes', { "in": RecordID('person', 'tobie'), "out": RecordID('post', 123) }) # Insert multiple records across tables people = db.insert_relation('likes', [ { "in": RecordID('person', 'tobie'), "out": RecordID('post', 123), }, { "in": RecordID('person', 'jaime'), "out": RecordID('post', 456), } ])

Translated query

This function will run the following query in the database.

INSERT RELATION INTO $table $data;