Re: SELECT FOR UPDATE performance is bad - Mailing list pgsql-performance

From Christopher Kings-Lynne
Subject Re: SELECT FOR UPDATE performance is bad
Date
Msg-id 44459EAF.2030601@calorieking.com
Whole thread Raw
In response to Re: SELECT FOR UPDATE performance is bad  (PFC <lists@peufeu.com>)
List pgsql-performance
> 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



pgsql-performance by date:

Previous
From: Tom Lane
Date:
Subject: Re: Planner doesn't chose Index - (slow select)
Next
From: Terje Elde
Date:
Subject: Re: Blocks read for index scans