Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 8EB7E633CF6 for ; Mon, 1 Jun 2009 01:56:59 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 63674-07 for ; Mon, 1 Jun 2009 01:56:56 -0300 (ADT) X-Greylist: delayed 00:56:44.249597 by SQLgrey-1.7.6 Received: from mail-qy0-f127.google.com (mail-qy0-f127.google.com [209.85.221.127]) by mail.postgresql.org (Postfix) with ESMTP id B250A6338B6 for ; Mon, 1 Jun 2009 01:56:57 -0300 (ADT) Received: by qyk33 with SMTP id 33so3412882qyk.15 for ; Sun, 31 May 2009 21:56:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=hFRWrK/MJB0HfB6dv9Av6G1i8q+d1rep+qF9NKjPoNg=; b=vai0VrPXd4Zckd4//USKv70hx4HOSScXP2tvW2Ok6zOCNyvEyj4lgtfO7YKiltRRhE XFCpVyT/S0m/owYGeg0FK2VeJkEw5M0/VvDXTyJkCaRn+PzJQESx7IoZ0OE9Hfd7dYSw BibA2B9rk/SbGDnnrQKaOixjR++BQmNiUfGGI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=VQqllLvym/mOFfZs0qhqUhbtgmtV+LfbRnc4oozKhXE12DUgeGVJ5dqL4U1b0Q6LHI jlIpXM0XWm+Ykag2TVggnAWs6fEPKDiLbnWYtiZloLdBmxc5Np1AqBFzt72yhGtENQzb 7jBK020lfd+525IgGgmjcOaSIV0jn4EdrtJxI= MIME-Version: 1.0 Received: by 10.229.80.3 with SMTP id r3mr1550078qck.104.1243831791655; Sun, 31 May 2009 21:49:51 -0700 (PDT) In-Reply-To: References: Date: Mon, 1 Jun 2009 14:49:51 +1000 Message-ID: Subject: Re: Assigning data-entry tasks to multiple concurrent clients From: Jamie Tufnell To: pgsql-sql@postgresql.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200906/1 X-Sequence-Number: 32606 Just want to correct a small but significant error in the first query: WHERE locked_since < now() + interval '5 minutes' Should read: WHERE locked_since BETWEEN now() - interval '5 minutes' AND now(); On 6/1/09, Jamie Tufnell wrote: > Hi, > > I am trying to provide a simple data entry interface to allow multiple > people to efficiently work through every record in a table and fill in the > missing values. > > The interface is a web application that simply loads up record after record > until they're all complete. > > I want to minimize the possibility of assigning the same record to two > users. > > Below is how I'm thinking of assigning records to clients for editing. The > idea is to pick a record for a user and remove it from the queue > temporarily. It re-enters the queue after 5 minutes if no edit has been > made. > > BEGIN; > SELECT * FROM records > WHERE in_edit_queue AND id NOT IN ( > SELECT record_id FROM locked_records > WHERE locked_since < now() + interval '5 minutes') > LIMIT 1; > > INSERT INTO locked_records (record_id, locked_since) VALUES (?, now()); > COMMIT; > > Then to save (first-in wins is acceptable for this environment): > > BEGIN; > UPDATE records SET in_edit_queue = false WHERE id = ? AND in_edit_queue = > true; > DELETE FROM locked_records WHERE record_id = ?; > COMMIT; > > Is this a sane approach? Is there a better way to do this with PostgreSQL? > > All feedback is greatly appreciated.. > > Cheers, > J. >