TiDBTiDB Docs Dash 2024

Jan 9 - Jan 12 (UTC)
Join us to improve docs and win a prize!
Sign InTry Free

BATCH

The BATCH syntax splits a DML statement into multiple statements in TiDB for execution. This means that there are no guarantees of transactional atomicity and isolation. Therefore, it is a "non-transactional" statement.

Currently, INSERT, REPLACE, UPDATE, and DELETE are supported in BATCH.

Based on a column, the BATCH syntax divides a DML statement into multiple ranges of scope for execution. In each range, a single SQL statement is executed.

For details about the usage and restrictions, see Non-transactional DML statements.

When you use multi-table join in a BATCH statement, you need to specify the full path of the column to avoid ambiguity:

BATCH ON test.t2.id LIMIT 1 INSERT INTO t SELECT t2.id, t2.v, t3.v FROM t2 JOIN t3 ON t2.k = t3.k;

The preceding statement specifies the column to be split as test.t2.id, which is unambiguous. If you use the id as follows, an error is reported:

BATCH ON id LIMIT 1 INSERT INTO t SELECT t2.id, t2.v, t3.v FROM t2 JOIN t3 ON t2.k = t3.k; Non-transactional DML, shard column must be fully specified

Synopsis

NonTransactionalDMLStmt
BATCHONColumnNameLIMITNUMDryRunOptionsShardableStmt
DryRunOptions
DRYRUNQUERY
ShardableStmt
DeleteFromStmtUpdateStmtInsertIntoStmtReplaceIntoStmt

MySQL compatibility

The BATCH syntax is TiDB-specific and not compatible with MySQL.

See also

Was this page helpful?

Download PDFRequest docs changesAsk questions on Discord
Playground
New
One-stop & interactive experience of TiDB's capabilities WITHOUT registration.
Products
TiDB
TiDB Dedicated
TiDB Serverless
Pricing
Get Demo
Get Started
© 2024 PingCAP. All Rights Reserved.
Privacy Policy.