START TRANSACTION
Function
Starts a transaction. If the isolation level or read/write mode is specified, a new transaction will have those characteristics. You can also specify them using SET TRANSACTION.
Precautions
None
Syntax
Format 1: START TRANSACTION
1 2 3 4 5 6 7 |
START TRANSACTION [ { ISOLATION LEVEL { READ COMMITTED | READ UNCOMMITTED | SERIALIZABLE | REPEATABLE READ } | { READ WRITE | READ ONLY } } [, ...] ]; |
Format 2: BEGIN
1 2 3 4 5 6 7 |
BEGIN [ WORK | TRANSACTION ] [ { ISOLATION LEVEL { READ COMMITTED | READ UNCOMMITTED | SERIALIZABLE | REPEATABLE READ } | { READ WRITE | READ ONLY } } [, ...] ]; |
Parameter Description
- WORK | TRANSACTION
Specifies the optional keyword in BEGIN format without functions.
- ISOLATION LEVEL
Specifies the transaction isolation level that determines the data that a transaction can view if other concurrent transactions exist.
The isolation level of a transaction cannot be reset after the first clause (INSERT, DELETE, UPDATE, FETCH, COPY) for modifying data is executed in the transaction.
Value range:
- READ COMMITTED: Only committed data is read. It is the default value.
- READ UNCOMMITTED: Uncommitted data is probably read. This isolation level is provided to handle CN breakdown emergencies. On this isolation level, you are advised to only read data to prevent inconsistency.
- REPEATABLE READ: Only the data committed before transaction start is read. Uncommitted data or data committed in other concurrent transactions cannot be read.
- SERIALIZABLE: Currently, this isolation level is not supported in GaussDB. It is equivalent to REPEATABLE READ.
- READ WRITE | READ ONLY
Specifies the transaction access mode (read/write or read only).
Examples
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
-- Start a transaction in default mode. openGauss=# START TRANSACTION; openGauss=# SELECT * FROM tpcds.reason; openGauss=# END; -- Start a transaction in default mode. openGauss=# BEGIN; openGauss=# SELECT * FROM tpcds.reason; openGauss=# END; -- Start a transaction with the isolation level being READ COMMITTED and the access mode being READ WRITE: openGauss=# START TRANSACTION ISOLATION LEVEL READ COMMITTED READ WRITE; openGauss=# SELECT * FROM tpcds.reason; openGauss=# COMMIT; |
Helpful Links
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot