Menu
Amazon Redshift
Database Developer Guide (API Version 2012-12-01)

ROLLBACK

Aborts the current transaction and discards all updates made by that transaction.

This command performs the same function as the ABORT command.

Syntax

Copy
ROLLBACK [ WORK | TRANSACTION ]

Parameters

WORK

Optional keyword.

TRANSACTION

Optional keyword; WORK and TRANSACTION are synonyms.

Example

The following example creates a table then starts a transaction where data is inserted into the table. The ROLLBACK command then rolls back the data insertion to leave the table empty.

The following command creates an example table called MOVIE_GROSS:

Copy
create table movie_gross( name varchar(30), gross bigint );

The next set of commands starts a transaction that inserts two data rows into the table:

Copy
begin; insert into movie_gross values ( 'Raiders of the Lost Ark', 23400000); insert into movie_gross values ( 'Star Wars', 10000000 );

Next, the following command selects the data from the table to show that it was successfully inserted:

Copy
select * from movie_gross;

The command output shows that both rows successfully inserted:

Copy
name | gross -------------------------+---------- Raiders of the Lost Ark | 23400000 Star Wars | 10000000 (2 rows)

This command now rolls back the data changes to where the transaction began:

Copy
rollback;

Selecting data from the table now shows an empty table:

Copy
select * from movie_gross; name | gross ------+------- (0 rows)