4 RELEASE SAVEPOINT — release a previously defined savepoint
8 RELEASE [ SAVEPOINT ] savepoint_name
12 RELEASE SAVEPOINT releases the named savepoint and all active
13 savepoints that were created after the named savepoint, and frees their
14 resources. All changes made since the creation of the savepoint that
15 didn't already get rolled back are merged into the transaction or
16 savepoint that was active when the named savepoint was created. Changes
17 made after RELEASE SAVEPOINT will also be part of this active
18 transaction or savepoint.
23 The name of the savepoint to release.
27 Specifying a savepoint name that was not previously defined is an
30 It is not possible to release a savepoint when the transaction is in an
31 aborted state; to do that, use ROLLBACK TO SAVEPOINT.
33 If multiple savepoints have the same name, only the most recently
34 defined unreleased one is released. Repeated commands will release
35 progressively older savepoints.
39 To establish and later release a savepoint:
41 INSERT INTO table1 VALUES (3);
42 SAVEPOINT my_savepoint;
43 INSERT INTO table1 VALUES (4);
44 RELEASE SAVEPOINT my_savepoint;
47 The above transaction will insert both 3 and 4.
49 A more complex example with multiple nested subtransactions:
51 INSERT INTO table1 VALUES (1);
53 INSERT INTO table1 VALUES (2);
55 INSERT INTO table1 VALUES (3);
56 RELEASE SAVEPOINT sp2;
57 INSERT INTO table1 VALUES (4))); -- generates an error
59 In this example, the application requests the release of the savepoint
60 sp2, which inserted 3. This changes the insert's transaction context to
61 sp1. When the statement attempting to insert value 4 generates an
62 error, the insertion of 2 and 4 are lost because they are in the same,
63 now-rolled back savepoint, and value 3 is in the same transaction
64 context. The application can now only choose one of these two commands,
65 since all other commands will be ignored:
67 ROLLBACK TO SAVEPOINT sp1;
69 Choosing ROLLBACK will abort everything, including value 1, whereas
70 ROLLBACK TO SAVEPOINT sp1 will retain value 1 and allow the transaction
75 This command conforms to the SQL standard. The standard specifies that
76 the key word SAVEPOINT is mandatory, but PostgreSQL allows it to be
81 BEGIN, COMMIT, ROLLBACK, ROLLBACK TO SAVEPOINT, SAVEPOINT