You are viewing the documentation for a prerelease version.

SET TRANSACTION

    +
    The SET TRANSACTION statement enables you to specify settings for a transaction.

    Purpose

    The SET TRANSACTION statement enables you to specify settings for an ACID transaction. Refer to Transactions for further information.

    This statement may only be used within a transaction.

    If you are using the Query Workbench or the Query REST API, you must set the txid query parameter to specify the transaction ID.

    If you are using the cbq shell, you don’t need to specify the transaction ID. Once you have started a transaction, all statements within the cbq shell session are assumed to be part of the same transaction until you rollback or commit the transaction. [1]

    You may also optionally specify settings when you start the transaction using the BEGIN TRANSACTION command.

    Currently, the only available transaction setting is "isolation level read committed". This setting is enabled by default. The SET TRANSACTION statement is therefore optional and may be omitted.

    Syntax

    set-transaction ::= SET TRANSACTION ISOLATION LEVEL READ COMMITTED
    'SET' 'TRANSACTION' 'ISOLATION' 'LEVEL' 'READ' 'COMMITTED'

    Examples

    Example 1. Specify transaction settings — cbq shell
    Request
    cbq> SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
    Example 2. Specify transaction settings — REST API
    CURL request
    $ curl http://localhost:8093/query/service \
    -u Administrator:password \
    -H 'Content-Type: application/json' \
    -d '{
      "statement": "SET TRANSACTION ISOLATION LEVEL READ COMMITTED;",
      "pretty": true,
      "txid": "d81d9b4a-b758-4f98-b007-87ba262d3a51" (1)
    }'
    1 The transaction ID generated when the transaction began.

    1. You must be using cbq shell version 2.0 or above to use the automatic transaction ID functionality.