INSERT SQL statement.
Before you begin
Before reading this page, do the following:- Create a CockroachDB Standard cluster or start a local cluster.
- Install a Driver or ORM Framework.
- Connect to the database.
When running under the default
SERIALIZABLE isolation level, your application should use a retry loop to handle transaction retry errors that can occur under contention.Insert rows
When inserting multiple rows, a single multi-row insert statement is faster than multiple single-row statements.- SQL
- Go
- Java
- Python
cockroach sql reference docs.Limit the size of rows
To help you avoid failures arising from misbehaving applications that bloat the size of rows, you can specify the behavior when a row or individual column family larger than a specified size is written to the database. Use the cluster settingssql.guardrails.max_row_size_log to discover large rows and sql.guardrails.max_row_size_err to reject large rows.
When you write a row that exceeds sql.guardrails.max_row_size_log:
INSERT,UPSERT,UPDATE,CREATE TABLE AS,CREATE INDEX,ALTER TABLE,ALTER INDEX,IMPORT, orRESTOREstatements will log aLargeRowto theSQL_PERFchannel.SELECT,DELETE,TRUNCATE, andDROPare not affected.
sql.guardrails.max_row_size_err:
INSERT,UPSERT, andUPDATEstatements will fail with a code54000 (program_limit_exceeded)error.CREATE TABLE AS,CREATE INDEX,ALTER TABLE,ALTER INDEX,IMPORT, andRESTOREstatements will log aLargeRowInternalevent to theSQL_INTERNAL_PERFchannel.SELECT,DELETE,TRUNCATE, andDROPare not affected.
sql.guardrails.max_row_size_log in conjunction with SELECT pg_column_size() queries to detect and fix any existing large rows before lowering sql.guardrails.max_row_size_err.
See also
Reference information related to this task:- Migration Overview
INSERTUPSERT- Transaction Contention
- Multi-row DML best practices
- Insert Multiple Rows

