Skip to main content

BatchResult

The result of PreparedStatement.executeBatch(). results holds every completed set. On success that's all of them; when the server rejects one, the batch stops there and the completed prefix is attached to the thrown DatabaseError as batchResults instead.

KeyTypeDefaultDescription
resultsBatchCommandResult[]One entry per parameter set, in submission order
totalRowsAffectednumberSum of every set's rowsAffected (the common bulk-write case)
fieldsFieldInfo[]Column descriptions, when the statement returns rows. One copy for the whole batch, since every set runs the same statement
executeTimenumberWall time for the whole batch, when timing is enabled

BatchCommandResult​

What one parameter set produced: exactly one per set, in the same order the sets were submitted in, since the server answers each Execute with its own CommandComplete.

KeyTypeDefaultDescription
commandstringThe command tag PostgreSQL reported for this set (INSERT/UPDATE/...)
rowsAffectednumberRows affected, for INSERT/UPDATE/DELETE/MERGE, as in QueryResult
rowsany[]Rows this set returned, decoded the same way execute() decodes them (rowDecoder included). Only present when the statement actually returns rows: a plain UPDATE without RETURNING leaves this undefined, not an empty array
const stmt = await connection.prepare('update users set name = $1 where id = $2');
const batch = await stmt.executeBatch([
['John', 1],
['Jane', 2],
['Bob', 3],
]);
batch.results.map(r => r.rowsAffected); // [1, 1, 0]
batch.totalRowsAffected; // 2

See Prepared Statements for the full guide.