Working with PostgreSQL transactions
PostgreSQL provides you with a highly advanced transaction machinery that offers countless features to developers and administrators alike. In this section, it is time to look at the basic concept.
The first important thing to know is this: in PostgreSQL, everything is a transaction. If you send a simple query to the server, it is already a transaction. Here is an example:
test=# SELECT now(), now(); now | now ------------------------------+------------------------------ 2016-08-30 12:03:27.84596+02 | 2016-08-30 12:03:27.84596+02 (1 row)
In this case, the SELECT
statement will be a separate transaction. If the same command is executed again, different timestamps will be returned.
Note
Keep in mind that the now()
function will return the transaction time. The SELECT
statement will, therefore, always return two identical timestamps.
If more than one statement has to be part of the same transactions, the BEGIN...