Re: Simple Atomic Relationship Insert
От | Jim Nasby |
---|---|
Тема | Re: Simple Atomic Relationship Insert |
Дата | |
Msg-id | 54B8603B.9010802@BlueTreble.com обсуждение исходный текст |
Ответ на | Re: Simple Atomic Relationship Insert ("Daniel Verite" <daniel@manitou-mail.org>) |
Список | 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 по дате отправления: