Re: Simple Atomic Relationship Insert - Mailing list pgsql-general

From Jim Nasby
Subject Re: Simple Atomic Relationship Insert
Date
Msg-id 54B8603B.9010802@BlueTreble.com
Whole thread Raw
In response to Re: Simple Atomic Relationship Insert  ("Daniel Verite" <daniel@manitou-mail.org>)
List pgsql-general
On 1/14/15 8:28 AM, Daniel Verite wrote:
>     Roxanne Reid-Bennett wrote:
>
>> >When you have a sequence of steps that need to be serialized across
>> >processes, choose or even create a table to use for locking
> This can also be done with an advisory lock, presumably faster:
> http://www.postgresql.org/docs/current/static/explicit-locking.html
>
> DECLARE
>     lock_key int := hashtext(hometown_name);
> BEGIN
>     SELECT pg_advisory_xact_lock(lock_key,0);
>     // check for existence and insert if it doesn't exist
> END;

I doubt that's going to be any faster than the preferred approach, which is documented in the ERROR TRAPPING section of
theplpgsql docs (Example 40-2):
http://www.postgresql.org/docs/devel/static/plpgsql-control-structures.html#PLPGSQL-ERROR-TRAPPING
--
Jim Nasby, Data Architect, Blue Treble Consulting
Data in Trouble? Get it in Treble! http://BlueTreble.com


pgsql-general by date:

Previous
From: Jim Nasby
Date:
Subject: Re: [HACKERS] can you have any idea about toast missing chunk issu resolution
Next
From: Jim Nasby
Date:
Subject: Re: "Ungroup" data for import into PostgreSQL