Skip to content

sql: pg mandates multi-stmt batches to execute as single txn #44803

@knz

Description

@knz

As per pg's docs: https://www.postgresql.org/docs/12/protocol-flow.html#PROTOCOL-FLOW-MULTI-STATEMENT

When a simple Query message contains more than one SQL statement (separated by semicolons), those statements are executed as a single transaction, unless explicit transaction control commands are included to force a different behavior. For example, if the message contains

INSERT INTO mytable VALUES(1);
SELECT 1/0;
INSERT INTO mytable VALUES(2);

then the divide-by-zero failure in the SELECT will force rollback of the first INSERT. Furthermore, because execution of the message is abandoned at the first error, the second INSERT is never attempted at all.

If a pg client that expects this behavior is ran against crdb, this will yield inconsistent data without any clear signal to the client.

(The current crdb behavior is a plain ACID violation when viewed through the lens of pg semantics.)

Epic CRDB-8948

Jira issue: CRDB-5201

Metadata

Metadata

Assignees

Labels

A-sql-executorSQL txn logicA-sql-pgcompatSemantic compatibility with PostgreSQLA-sql-pgwirepgwire protocol issues.C-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.T-sql-foundationsSQL Foundations Team (formerly SQL Schema + SQL Sessions)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions