Re: BUG #13920: pg_try_advisory_xact_lock bigint trouble

From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: "Valeriy A(dot)" <mtakvel(at)gmail(dot)com>
Cc: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, "pgsql-general(at)postgresql(dot)org" <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #13920: pg_try_advisory_xact_lock bigint trouble
Date: 2016-03-04 21:17:07
Message-ID: CAHyXU0xn=gsEObRjr_HOChtcFQZBVUCATReRvp9=HtXmhO1nuw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Tue, Feb 9, 2016 at 3:01 AM, Valeriy A. <mtakvel(at)gmail(dot)com> wrote:
> Here my simple example
>
> --- SQL Begin
> create table table1 (
> id bigserial PRIMARY KEY
> -- other fields);
>
> create table table2 (
> id bigserial PRIMARY KEY
> -- other fields);
>
>
> CREATE FUNCTION do_action_on_table1(keyID bigint ) returns int2 LANGUAGE
> plpgsql AS $$
> DECLARE
> isLocked boolean;
> BEGIN
> EXECUTE 'SELECT pg_try_advisory_xact_lock($1)' INTO isLocked USING keyID;
>
> if isLocked THEN
> --SOME action on table1
> RETURN 1;
> END IF;
>
> RETURN 0;
> END$$
>
> CREATE FUNCTION do_action_on_table2(keyID bigint ) returnS int2
> LANGUAGE plpgsql
> AS $$
> DECLARE
> isLocked boolean;
> BEGIN
> EXECUTE 'SELECT pg_try_advisory_xact_lock($1)' INTO isLocked USING keyID;
>
> if isLocked THEN
> --SOME action on table2
> RETURN 1;
> END IF;
>
> RETURN 0;
> END$$
> -- SQL End

The problenm is
you can do it via:
create sequence lock_seq;
create domain lockid bigint default nextval('lock_seq');

create table table1 (
id lockid PRIMARY KEY
-- other fields);

create table table2 (
id lockid PRIMARY KEY
-- other fields);

...

merlin

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Andres Freund 2016-03-05 07:47:28 Re: BUG #13844: Logical decoding bug with subxact + row locking
Previous Message Thomas Munro 2016-03-04 19:15:14 Re: BUG #13920: pg_try_advisory_xact_lock bigint trouble