Skip site navigation (1) Skip section navigation (2)

Re: Atomic/locked "allocation" of table row?

From: Rodrigo De León <rdeleonp(at)gmail(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: Atomic/locked "allocation" of table row?
Date: 2007-08-06 03:44:29
Message-ID: 1186371869.486283.231530@o61g2000hsh.googlegroups.com (view raw or flat)
Thread:
Lists: pgsql-novice
On Aug 5, 9:02 pm, netsli(dot)(dot)(dot)(at)gmail(dot)com (Sten Daniel Soersdal) wrote:
> Help?

SELECT FOR UPDATE:

http://www.postgresql.org/docs/8.2/static/sql-select.html#SQL-FOR-UPDATE-SHARE

-- Example --
CREATE OR REPLACE FUNCTION FOO(MYSECRET TEXT) RETURNS INT AS
$$
DECLARE
  U INT;
BEGIN
  SELECT USERNAME
  INTO U
  FROM TUNNEL
  WHERE PASSWORD IS NULL LIMIT 1 FOR UPDATE;
  UPDATE TUNNEL SET PASSWORD = MYSECRET WHERE USERNAME = U;
  RETURN U;
END;
$$ LANGUAGE PLPGSQL;


In response to

pgsql-novice by date

Next:From: Richard Broersma JrDate: 2007-08-06 13:56:29
Subject: Re: Atomic/locked "allocation" of table row?
Previous:From: Sten Daniel SoersdalDate: 2007-08-06 02:02:30
Subject: Atomic/locked "allocation" of table row?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group