Website logo
⌘K
🏠Homepage
πŸ‘‹Introduction
Key Concepts & Architecture
πŸš€Run Oxla in 2 minutes
πŸƒβ€β™‚οΈRun Oxla on S3
πŸ›«Multi-node Deployment
πŸ‘¨β€πŸ’»SQL Reference
SQL Queries
SQL Clauses
SQL Data Types
SQL Functions
Schema
Comment Support
⛓️SQL Mutations
DELETE
UPDATE
🚨Error Handling
πŸ†šDifferences Between Oxla vs. PostgreSQL
πŸ”„Understanding Transactions
πŸ“ˆPublic Metrics
βš™οΈOxla Configuration File
✨Changelog
Docs powered byΒ Archbee

Understanding Transactions

10min

1. Overview

The transactions are supported only on the syntax level to allow integration with tools that requires it. While the syntax is accepted, all the queries are executed immediately and with no transactional guarantees.

2. Commands

These commands are used to manage transactions:

2.1. BEGIN

Initiates a new transaction.

Syntax

Pgsql
BEGIN;
ο»Ώ

or

Pgsql
BEGIN TRANSACTION;
ο»Ώ

2.2. COMMIT

Saves the changes made in a transaction to the database. It simply ends the transaction.

Syntax

Pgsql
COMMIT;
ο»Ώ

or

Pgsql
END TRANSACTION;
ο»Ώ

2.3. ROLLBACK

In Oxla, when you issue a ROLLBACK command, it doesn't undo changes made in the current transaction. It simply finishes the transaction without any rollback action.

Syntax

Pgsql
ROLLBACK;
ο»Ώ

3. Example

1) Let’s define a table named products with columns: product_name, price, and stock_quantity.

Pgsql
CREATE TABLE productsnew(
    product_name TEXT,
    price INT,
    stock_quantity INT
);
ο»Ώ
Pgsql
COMPLETE
ο»Ώ

2) Next, we want to insert product data into a products table.

Pgsql
BEGIN;

INSERT INTO productsnew(product_name, price, stock_quantity) VALUES ('Tab', 8000, 20);
INSERT INTO productsnew(product_name, price, stock_quantity) VALUES ('Laptop', 10000, 32);
INSERT INTO productsnew(product_name, price, stock_quantity) VALUES ('Harddisk', 12000, 14);
ο»Ώ

The INSERT statement is executed immediately without waiting for the end of the transaction or until a COMMIT is issued.

You will get the following output:

Pgsql
BEGIN
INSERT 0 1
INSERT 0 1
INSERT 0 1
ο»Ώ

3) View the changes by displaying the products table:

Pgsql
SELECT * FROM productsnew;
COMMIT; -- or ROLLBACK;
ο»Ώ

The product data is now added to the table.

Pgsql
 product_name | price | stock_quantity 
--------------+-------+----------------
 Harddisk     | 12000 |             14
 Tab          |  8000 |             20
 Laptop       | 10000 |             32
(3 rows)

COMMIT
ο»Ώ

ο»Ώ

Updated 22 Nov 2023
Did this page help you?
PREVIOUS
Differences Between Oxla vs. PostgreSQL
NEXT
Public Metrics
Docs powered byΒ Archbee
TABLE OF CONTENTS
1. Overview
2. Commands
2.1. BEGIN
2.2. COMMIT
2.3. ROLLBACK
3. Example
Docs powered byΒ Archbee

Β©2023 Oxla