Suppose you have a table codes :
(
    game_id    INT,
    code        TEXT,
    used        BOOL NOT NULL DEFAULT 'f',
    prize        ...
    ...
    PRIMARY KEY (game_id, code)
)

Just UPDATE codes SET used='t' WHERE used='f' AND game_id=... AND code=...

Then check the rowcount : if one row was updated, the code was not used yet. If no row was updated, the code either did not exist, or was already used.

You can use a stored procedure with exceptions no?

Try this:

http://www.postgresql.org/docs/8.1/interactive/plpgsql-control-structures.html#PLPGSQL-UPSERT-EXAMPLE

Chris



---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
      subscribe-nomail command to [EMAIL PROTECTED] so that your
      message can get through to the mailing list cleanly

Reply via email to