Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine if a transaction is active (Postgres)

Tags:

postgresql

How can I determine if a transaction is active? I'd like to be able to execute SQL that creates a savepoint regardless of whether or not a transaction is currently active (i.e. if it isn't active, I want to "BEGIN")

like image 674
hadley Avatar asked Feb 12 '15 19:02

hadley


1 Answers

You can do

begin;
savepoint foo;

The "begin;" will be a no-op if there is a transaction already.

Also see: https://stackoverflow.com/a/28802471/435563

like image 112
shaunc Avatar answered Oct 05 '22 00:10

shaunc