Skip to main content
This page has instructions for getting data into CockroachDB with various programming languages, using the SQL statement.

Before you begin

Before reading this page, do the following:
  • or .
  • .
  • .
When running under the default isolation level, your application should that can occur under .

Insert rows

When inserting multiple rows, a single is faster than multiple single-row statements.
For more information about how to use the built-in SQL client, see the reference docs.
For complete examples, see:
  • (pgx)
For complete examples, see:
  • (JDBC)
For complete examples, see:
  • (psycopg3)

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 larger than a specified size is written to the database. Use the sql.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, or RESTORE statements will log a LargeRow to the channel.
  • SELECT, DELETE, TRUNCATE, and DROP are not affected.
When you write a row that exceeds sql.guardrails.max_row_size_err:
  • INSERT, UPSERT, and UPDATE statements will fail with a code 54000 (program_limit_exceeded) error.
  • CREATE TABLE AS, CREATE INDEX, ALTER TABLE, ALTER INDEX, IMPORT, and RESTORE statements will log a LargeRowInternal event to the channel.
  • SELECT, DELETE, TRUNCATE, and DROP are not affected.
You cannot update existing rows that violate the limit unless the update shrinks the size of the row below the limit. You can select, delete, alter, back up, and restore such rows. We recommend using the accompanying setting 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:
Other common tasks: