Re: [SQL] Are PL/pgSQL calls atomic?

From: Vadim Mikheev <vadim(at)krs(dot)ru>
To: Mark Wright <mwright(at)pro-ns(dot)net>
Cc: pgsql-sql(at)postgreSQL(dot)org
Subject: Re: [SQL] Are PL/pgSQL calls atomic?
Date: 1999-06-03 01:24:56
Message-ID: 3755D968.D3955172@krs.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Mark Wright wrote:
>
> If I call a PL/pgSQL function, and another client makes the same call, does
> the second client have to wait for the first to complete execution before it
> begins? If not, is there some sort of mechanism I can use to prevent more
> than one call to a function from happening at the same time (something like
> a mutex in Win32).
>
> I need to select a row and then mark it as unavailable for other clients to
> use. The table looks like:
> create table xyz (id serial, status char default 'N', ...);
>
> My function finds a row by doing:
> select id into my_id_variable from xyz where id
> = (select min(id) from xyz where status = 'N');

6.5 allows you SELECT FOR UPDATE...

>
> and then marks that row as unavailable by setting status:
> update xyz set status = 'Y' where id = my_id_variable;
>
> Obviously, if a second client calls this function before the UPDATE takes
> place, it will pick up the same row as the first client, causing rending of
> hair and gnashing of teeth.

Vadim

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Herbert Ambos 1999-06-03 01:40:54 RE: [SQL] Column name's length
Previous Message D'Arcy J.M. Cain 1999-06-02 22:54:33 Re: [SQL] Getting primary key from insert statement