Re: Locking vs. Exceptions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Robins wrote:
Hi,

The documentation says that function blocks with exceptions are far costlier than without one.


I recommend against using exceptions. There is a memory leak in the exception handler that will cause headaches if it is called many times in the transaction.

In plpgsql, I would use:

SELECT ... FOR UPDATE;
IF FOUND THEN
	UPDATE ...;
ELSE
	INSERT ...;
END IF;


If you have multiple transactions doing this process at the same time, you'll need explicit locking of the table to avoid a race condition.

--
Benjamin Minshall <minshall@xxxxxxxxxxxxxx>
Senior Developer -- Intellicon, Inc.
http://www.intellicon.biz


[Postgresql General]     [Postgresql PHP]     [PHP Users]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Yosemite]

  Powered by Linux