Re: Locking vs. Exceptions

From: Benjamin Minshall <minshall(at)intellicon(dot)biz>
To: robins(at)pobox(dot)com
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Locking vs. Exceptions
Date: 2006-11-02 23:17:47
Message-ID: 454A7C9B.40207@intellicon.biz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

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(at)intellicon(dot)biz>
Senior Developer -- Intellicon, Inc.
http://www.intellicon.biz

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Arjen van der Meijden 2006-11-03 09:39:08 Re: Query plan for "heavy" SELECT with "lite" sub-SELECTs
Previous Message Vivek Khera 2006-11-02 21:41:35 Re: VACUUMs take twice as long across all nodes