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
Views: Raw Message | Whole Thread | Download mbox | Resend email
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

Browse pgsql-novice by date

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