バージョンごとのドキュメント一覧

RELEASE SAVEPOINT

RELEASE SAVEPOINT <refpurpose>release a previously defined savepoint</refpurpose> — 設定済みのセーブポイントを解放する

概要

RELEASE [ SAVEPOINT ] savepoint_name

説明

<title>Description</title>

<command>RELEASE SAVEPOINT</command> releases the named savepoint and all active savepoints that were created after the named savepoint, and frees their resources. All changes made since the creation of the savepoint that didn't already get rolled back are merged into the transaction or savepoint that was active when the named savepoint was created. Changes made after <command>RELEASE SAVEPOINT</command> will also be part of this active transaction or savepoint. RELEASE SAVEPOINTは指定されたセーブポイントと、指定されたセーブポイントの後に作成されたすべての有効なセーブポイントを解放し、そのリソースを解放します。 セーブポイントの作成後に行われたすべての変更で、まだロールバックされていないものは、指定されたセーブポイントが作成されたときに実行中のトランザクションまたは有効なセーブポイントにマージされます。 RELEASE SAVEPOINTの後に行われた変更も、この実行中のトランザクションまたは有効なセーブポイントの一部になります。

パラメータ

<title>Parameters</title>
savepoint_name

The name of the savepoint to release. 解放するセーブポイントの名前です。

注釈

<title>Notes</title>

Specifying a savepoint name that was not previously defined is an error. 設定されていないセーブポイント名を指定するとエラーになります。

It is not possible to release a savepoint when the transaction is in an aborted state; to do that, use <xref linkend="sql-rollback-to"/>. トランザクションがアボート状態の時には、セーブポイントを解放することはできません。 そのためには、ROLLBACK TO SAVEPOINTを使用してください。

If multiple savepoints have the same name, only the most recently defined unreleased one is released. Repeated commands will release progressively older savepoints. 同じ名前のセーブポイントが複数存在する場合、最後に設定されたセーブポイントのみが解放されます。 コマンドを繰り返すと、より以前のセーブポイントが順次解放されます。

<title>Examples</title>

To establish and later release a savepoint: セーブポイントを設定し、その後、解放します。

BEGIN;
    INSERT INTO table1 VALUES (3);
    SAVEPOINT my_savepoint;
    INSERT INTO table1 VALUES (4);
    RELEASE SAVEPOINT my_savepoint;
COMMIT;

The above transaction will insert both 3 and 4. 上記のトランザクションでは、3と4の両方が挿入されます。

A more complex example with multiple nested subtransactions: 複数の入れ子になったサブトランザクションを持つ、より複雑な例。

BEGIN;
    INSERT INTO table1 VALUES (1);
    SAVEPOINT sp1;
    INSERT INTO table1 VALUES (2);
    SAVEPOINT sp2;
    INSERT INTO table1 VALUES (3);
    RELEASE SAVEPOINT sp2;

    INSERT INTO table1 VALUES (4))); &#45;- generates an error

    INSERT INTO table1 VALUES (4))); -- エラーになる

In this example, the application requests the release of the savepoint <literal>sp2</literal>, which inserted 3. This changes the insert's transaction context to <literal>sp1</literal>. When the statement attempting to insert value 4 generates an error, the insertion of 2 and 4 are lost because they are in the same, now-rolled back savepoint, and value 3 is in the same transaction context. The application can now only choose one of these two commands, since all other commands will be ignored: この例では、アプリケーションがセーブポイントsp2の解放を要求し、そこでは3が挿入されています。 これにより、挿入のトランザクションコンテキストがsp1に変更されます。 値4を挿入しようとする文がエラーになると、同じロールバックされたセーブポイントにあるため、2と4の挿入は失われます。値3は同じトランザクションコンテキストにあります。 他のコマンドはすべて無視されるため、アプリケーションは今や以下の2つのコマンドのうち1つのみを選択できます。

   ROLLBACK;
   ROLLBACK TO SAVEPOINT sp1;

Choosing <command>ROLLBACK</command> will abort everything, including value 1, whereas <command>ROLLBACK TO SAVEPOINT sp1</command> will retain value 1 and allow the transaction to continue. ROLLBACKを選択すると、値1を含むすべてのコマンドがアボートされますが、ROLLBACK TO SAVEPOINT sp1を選択すると、値1が保持され、トランザクションの続行が可能になります。

互換性

<title>Compatibility</title>

This command conforms to the <acronym>SQL</acronym> standard. The standard specifies that the key word <literal>SAVEPOINT</literal> is mandatory, but <productname>PostgreSQL</productname> allows it to be omitted. このコマンドは標準SQLに準拠しています。 SQL:2003標準では、SAVEPOINTは必須であると規定されています。 PostgreSQLではSAVEPOINTキーワードを省略することができます。

関連項目

<title>See Also</title> BEGIN, COMMIT, ROLLBACK, ROLLBACK TO SAVEPOINT, SAVEPOINT