Re: Simple Atomic Relationship Insert

From: Jim Nasby <Jim(dot)Nasby(at)BlueTreble(dot)com>
To: Daniel Verite <daniel(at)manitou-mail(dot)org>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: Simple Atomic Relationship Insert
Date: 2015-01-16 00:50:03
Message-ID: 54B8603B.9010802@BlueTreble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 the plpgsql 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jim Nasby 2015-01-16 00:56:00 Re: "Ungroup" data for import into PostgreSQL
Previous Message Jim Nasby 2015-01-16 00:30:26 Re: can you have any idea about toast missing chunk issu resolution