pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Christopher Kings-Lynne <chris.kings-lynne@calorieking.com>
To: PFC <lists@peufeu.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: mario.splivalo@mobart.hr
Cc: pgsql-performance@postgresql.org
Subject: Re: SELECT FOR UPDATE performance is bad
Date: Wed, 19 Apr 2006 10:21:35 +0800
Message-ID: <44459EAF.2030601@calorieking.com> (raw)
In-Reply-To: <op.s77qveghcigqcu@apollo13>
References: <1145365720.18469.35.camel@localhost.localdomain>
	<13037.1145370658@sss.pgh.pa.us>
	<1145371662.31555.10.camel@localhost.localdomain>
	<13609.1145374386@sss.pgh.pa.us>
	<op.s77qveghcigqcu@apollo13>

> 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-EXAMPL...

Chris





view thread (8+ messages)  latest in thread

Message-ID: <44459EAF.2030601@calorieking.com>
Permalink:  ../44459EAF.2030601@calorieking.com/
Also on:    postgresql.org/message-id/44459EAF.2030601@calorieking.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: chris.kings-lynne@calorieking.com, lists@peufeu.com, tgl@sss.pgh.pa.us, mario.splivalo@mobart.hr
  Subject: Re: SELECT FOR UPDATE performance is bad
  In-Reply-To: <44459EAF.2030601@calorieking.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox