Postgresql is automatically submitted by default
Check whether it is an automatic submission:
postgres=# \echo :AUTOCOMMIT on
Turn off automatic submission:
postgres=# \set AUTOCOMMIT off postgres=# \echo :AUTOCOMMIT off
Another way is to start with begin at the beginning at the beginning of the session, which is equivalent to turning off automatic commit, and end with end or commit.
Supplement: pg (hgdb) default transaction automatically commits
By default, AUTOCOMMIT (autocommit) is open, which means that after any SQL statement is executed, the data modifications made by its lock will be submitted immediately. In this case, each statement is an independent transaction, and once the execution is completed, the result is irrevocable.
If you need to run a large number of DML statements and these statements have not been fully tested, the automatic submission function will cause trouble. At this time, it is necessary to turn off the automatic transaction handover mechanism to protect the data.
Please turn off the automatic submission function first: \set AUTOCOMMIT off, and then you can roll back the transaction as needed:
update set short_name='this is a mistake.';
To roll back a transaction, execute:
rollback;
The above is personal experience. I hope you can give you a reference and I hope you can support me more. If there are any mistakes or no complete considerations, I would like to give you advice.