multiple SAVEPOINTs without RELEASE SAVEPOINT

From: fearless_fool <rdpoor(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: multiple SAVEPOINTs without RELEASE SAVEPOINT
Date: 2012-07-13 21:05:00
Message-ID: 1342213500675-5716594.post@n5.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Is there any penalty for repeatedly doing
SAVEPOINT eugene
without a corresponding
RELEASE SAVEPOINT
?

In my case, I have a table with a unique index constraint. Multiple
processes will be trying to "create or lookup" a record, so trapping the
unique index constraint seems the most robust way to detect if the record
already exists. The overall structure I'm using (in pseudo-Ruby syntax):

begin
response = execute("SAVEPOINT eugene;
INSERT INTO symbols (name) VALUES
('#{name}') RETURNING id")
rescue
# arrive here on a constraint violation if the name already existed
response = execute("ROLLBACK TO SAVEPOINT eugene;
SELECT id FROM symbols WHERE symbols.name =
'#{name}'")
ensure
# is this RELEASE strictly required?
execute("RELEASE SAVEPOINT eugene")
end

(On a related note, would I be better off using advisory locks? And would
that be sufficient in the face of multiple processes?)

--
View this message in context: http://postgresql.1045698.n5.nabble.com/multiple-SAVEPOINTs-without-RELEASE-SAVEPOINT-tp5716594.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

Browse pgsql-general by date

  From Date Subject
Next Message Perry Smith 2012-07-14 15:57:30 Help me follow...
Previous Message Merlin Moncure 2012-07-13 18:42:30 great infoworld article on postgresql/enterprisedb