On Aug 5, 9:02 pm, netsli...@gmail.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;