Re: MOVE

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: PFC <lists(at)boutiquenumerique(dot)com>
Cc: Postgres general mailing list <pgsql-general(at)postgresql(dot)org>
Subject: Re: MOVE
Date: 2005-01-14 21:28:57
Message-ID: 20050114212852.GE1724@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

On Fri, Jan 14, 2005 at 08:49:24PM +0100, PFC wrote:
> the auto-expiration cron
> job, I must also expire ALL his open chatroom connections.
> INSERT INTO archive (...) SELECT ... FROM active WHERE user_id = ...;
> DELETE FROM active WHERE user_id = ...;
>
> Now, if the user inserts a connection between the two queries above, the
> thing will fail (the
> connection will just be deleted). I know that there are many ways to do it
> right :

Why not just do it in a single transaction? I don't think you need to
use SERIALIZABLE at all, I think normal read-committed mode will do
what you want, no?

BEGIN;
INSERT INTO archive (...) SELECT ... FROM active WHERE user_id = ...;
DELETE FROM active WHERE user_id = ...;
COMMIT;

The DELETE can only delete the rows returned by the select, that's the
whole point of transactions...

Hope this helps,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

In response to

  • MOVE at 2005-01-14 19:49:24 from PFC

Responses

  • Re: MOVE at 2005-01-14 21:55:47 from Tom Lane
  • Re: MOVE at 2005-01-15 00:07:47 from PFC

Browse pgsql-general by date

  From Date Subject
Next Message Dave Smith 2005-01-14 21:30:04 Re: MOVE
Previous Message John Sidney-Woollett 2005-01-14 21:04:12 Re: C locale + unicode

Browse pgsql-hackers by date

  From Date Subject
Next Message Kris Jurka 2005-01-14 21:54:02 Re: Time span conversion function
Previous Message Tom Lane 2005-01-14 21:19:47 Re: FATAL: catalog is missing 1 attribute(s) for relid 16396