pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Mark Wright <mwright@pro-ns.net>
To: pgsql-sql@postgresql.org
Subject: Are PL/pgSQL calls atomic?
Date: Wed, 2 Jun 1999 17:18:19 -0500
Message-ID: <001f01bead45$d72f9100$c62812ac@markw_compaq> (raw)

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');

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.

How do I prevent this?

Mark.
---
Mark Wright
mwright@pro-ns.net
mark_wright@datacard.com





view thread (4+ messages)  latest in thread

Message-ID: <001f01bead45$d72f9100$c62812ac@markw_compaq>
Permalink:  ../001f01bead45$d72f9100$c62812ac@markw_compaq/
Also on:    postgresql.org/message-id/001f01bead45$d72f9100$c62812ac@markw_compaq

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: mwright@pro-ns.net
  Subject: Re: Are PL/pgSQL calls atomic?
  In-Reply-To: <001f01bead45$d72f9100$c62812ac@markw_compaq>
  References: <001f01bead45$d72f9100$c62812ac@markw_compaq>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox