// dialect comparison

How many rows one INSERT can take

Every engine caps a single INSERT somewhere. Here is where the ceilings are.

Filed under Inserting & updating

The verdict

None of these limits bite until you batch thousands of rows, and at that point a bulk loader is the right tool anyway: COPY, BULK INSERT, LOAD DATA or SQL*Loader, or a staging table plus INSERT ... SELECT.

Where they differ

The limits differ in kind. SQL Server caps a VALUES list at 1,000 rows and a request at 2,100 parameters; MySQL bounds the statement's size in bytes by max_allowed_packet; SQLite caps bind parameters; PostgreSQL's wire protocol allows 65,535 parameters per statement. Past the cap, use INSERT ... SELECT from a staging table or the engine's bulk loader.

How each engine writes it

SQL Server

INSERT INTO logs (msg) VALUES ('a'), ('b'); -- 1000 rows max

1,001 rows fail with error 10738. A parameterized request is also capped at 2,100 parameters. INSERT … SELECT has no row cap, and BULK INSERT or bcp handle large loads.

PostgreSQL

INSERT INTO logs (msg) VALUES ('a'), ('b'), ('c');

No row cap. A parameterized statement can carry at most 65,535 parameters, so batch, or use COPY for big loads.

MySQL

INSERT INTO logs (msg) VALUES ('a'), ('b'), ('c');

No row cap; max_allowed_packet (64 MB by default in 8.0) bounds the statement's bytes. Keep batches well under it.

SQLite

INSERT INTO logs (msg) VALUES ('a'), ('b'), ('c');

Bound parameters are capped by SQLITE_MAX_VARIABLE_NUMBER: 999 before 3.32, 32,766 since, changeable at compile time. Literal values don't count; the statement as a whole is capped at 1,000,000,000 bytes (SQLITE_MAX_SQL_LENGTH).

Oracle

INSERT ALL
  INTO logs (msg) VALUES ('a')
  INTO logs (msg) VALUES ('b')
SELECT * FROM dual;

Works on every version; 23ai also takes a multi-row VALUES list. Large loads use INSERT /*+ APPEND */ … SELECT, array binds (FORALL in PL/SQL), SQL*Loader or external tables.

Questions that come up

Why 2,100 parameters in SQL Server?

It is SQL Server's documented maximum of parameters per stored procedure or parameterized request, which is what drivers send. Batching libraries therefore cap a batch at about 2,000 parameters: a 10-column insert fits about 200 rows per statement.

Is a huge multi-row INSERT one transaction?

It is one statement, and statements are atomic, so on transactional tables either every row lands or none do. A giant statement therefore holds locks and log or undo space like a giant transaction.

What is the fastest bulk path per engine?

PostgreSQL: COPY. MySQL: LOAD DATA INFILE. SQL Server: BULK INSERT, bcp or the driver's bulk-copy API. SQLite: one prepared INSERT executed repeatedly inside a single transaction. Oracle: SQL*Loader direct path or INSERT /*+ APPEND */.

Keep reading

// write it once, run it anywhere

Switch engines without relearning SQL

SQLly is a native SQL workbench for macOS, Windows and Linux. Its formatter and plan viewer work in all five dialects.