ABORT
Synopsis
Use the ABORT
statement to roll back the current transaction and discards all updates by the transaction.
Syntax
abort ::= ABORT [ TRANSACTION | WORK ]
abort
Semantics
abort
ABORT [ TRANSACTION | WORK ]
WORK
Add optional keyword — has no effect.
TRANSACTION
Add optional keyword — has no effect.
- The
SERIALIZABLE
isolation level not yet supported. (This is currently in progress). - Currently YugabyteDB will always use the snapshot isolation level internally. For more information, see Transaction isolation levels.
Examples
Create a sample table.
yugabyte=# CREATE TABLE sample(k1 int, k2 int, v1 int, v2 text, PRIMARY KEY (k1, k2));
Begin a transaction and insert some rows.
yugabyte=# BEGIN TRANSACTION; SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;
yugabyte=# INSERT INTO sample(k1, k2, v1, v2) VALUES (1, 2.0, 3, 'a'), (1, 3.0, 4, 'b');
Open the YSQL shell (ysqlsh
) and begin another transaction to insert some more rows.
yugabyte=# BEGIN TRANSACTION; SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;
yugabyte=# INSERT INTO sample(k1, k2, v1, v2) VALUES (2, 2.0, 3, 'a'), (2, 3.0, 4, 'b');
In each shell, check the only the rows from the current transaction are visible.
First shell.
yugabyte=# SELECT * FROM sample; -- run in first shell
k1 | k2 | v1 | v2
----+----+----+----
1 | 2 | 3 | a
1 | 3 | 4 | b
(2 rows)
Second shell.
yugabyte=# SELECT * FROM sample; -- run in second shell
k1 | k2 | v1 | v2
----+----+----+----
2 | 2 | 3 | a
2 | 3 | 4 | b
(2 rows)
Commit the first transaction and abort the second one.
yugabyte=# COMMIT TRANSACTION; -- run in first shell.
Abort the current transaction (from the first shell).
yugabyte=# ABORT TRANSACTION; -- run second shell.
In each shell, check that only the rows from the committed transaction are visible.
yugabyte=# SELECT * FROM sample; -- run in first shell.
k1 | k2 | v1 | v2
----+----+----+----
1 | 2 | 3 | a
1 | 3 | 4 | b
(2 rows)
yugabyte=# SELECT * FROM sample; -- run in second shell.
k1 | k2 | v1 | v2
----+----+----+----
1 | 2 | 3 | a
1 | 3 | 4 | b
(2 rows)
See also
当前内容版权归 YugabyteDB 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 YugabyteDB .