reliable lock inside stored procedure - Mailing list pgsql-sql

From Sebastian Böhm
Subject reliable lock inside stored procedure
Date
Msg-id 27682F23-349D-4728-AE95-68FB6D6FE881@seb.exse.net
Whole thread Raw
Responses Re: reliable lock inside stored procedure
List pgsql-sql
Hi,

I have a stored procedure and I need a SHARE ROW EXCLUSIVE lock in  
this procedure (otherwise data will get corrupted).

According to the documentation the LOCK statement is useless and will  
silently fail if not executed inside a transaction. (btw: this sounds  
dangerous to me)

Also it is not possible to start a transaction inside a stored  
procedure.

How can I make the code of this stored procedure safe?

is there a way to let the procedure fail with an error if not executed  
within a transaction.

does adding a SAVEPOINT the trick?
documentation says that savepoints can only be established inside  
transactions, but does it fail fatal enough so that the procedure  
getss aborted? (more fatal than LOCK does?)


thank you very much.
/sebastian



pgsql-sql by date:

Previous
From: Bryce Nesbitt
Date:
Subject: Re: Seq scan on join, not on subselect? analyze this
Next
From: Richard Huxton
Date:
Subject: Re: reliable lock inside stored procedure