X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 9B3119DC848 for ; Mon, 13 Feb 2006 13:33:10 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 73397-05 for ; Mon, 13 Feb 2006 13:33:09 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from floppy.pyrenet.fr (news.pyrenet.fr [194.116.145.2]) by postgresql.org (Postfix) with ESMTP id 1F03F9DC846 for ; Mon, 13 Feb 2006 13:33:08 -0400 (AST) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id 4D3733093C; Mon, 13 Feb 2006 18:33:07 +0100 (MET) From: "Alfred" <99m@myway.com> X-Newsgroups: pgsql.sql Subject: Tough Problem -- Record Checkouts Date: 13 Feb 2006 09:33:01 -0800 Organization: http://groups.google.com Lines: 29 Message-ID: <1139851981.176833.302970@g43g2000cwa.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Complaints-To: groups-abuse@google.com User-Agent: G2/0.2 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.12) Gecko/20051010 Firefox/1.0.7 (Ubuntu package 1.0.7),gzip(gfe),gzip(gfe) X-HTTP-Via: 1.1 tinyproxy (tinyproxy/1.6.3) Complaints-To: groups-abuse@google.com Injection-Info: g43g2000cwa.googlegroups.com; posting-host=198.246.222.7; posting-account=tqq99Q0AAADP9CEVFxMZ5eMrq3NNKdyf To: pgsql-sql@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200602/226 X-Sequence-Number: 24236 Imagine a library of books. Each book is a record. The library is the table. A user may check out a book and the shelf space it once occupied will store the minute that the user checked the book out. Every 5 minutes, a magical librarian walks through the library and when a book has been checked out longer than 15 minutes, she has the power to zap it back out of the user's hands and put it back on the shelf for someone else. How do you efficiently achieve this in a WHERE clause in SQL? For instance, here's a table of several minute columns. CO, in this case, is the checked out minute. N, in this case, is the current minute. This translates to, "If the CO = x, and N is within this range, then clear the CO column." CO | N ------+----------------------- 0 | 15-59 1 | 0, 16-59 2 | 0-1, 17-59 15 | 0-14, 30-59 16 | 0-15, 31-59 30 | 0-29, 45-59 31 | 0-30, 46-59 45 | 0-44 46 | 1-45 59 | 14-58 This becomes some kind of UPDATE statement with a complex WHERE clause.