pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alfred <99m@myway.com>
To: pgsql-sql@postgresql.org
Subject: Tough Problem -- Record Checkouts
Date: 13 Feb 2006 09:33:01 -0800
Message-ID: <1139851981.176833.302970@g43g2000cwa.googlegroups.com> (raw)

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.




view thread (2+ messages)  latest in thread

Message-ID: <1139851981.176833.302970@g43g2000cwa.googlegroups.com>
Permalink:  ../1139851981.176833.302970@g43g2000cwa.googlegroups.com/
Also on:    postgresql.org/message-id/1139851981.176833.302970@g43g2000cwa.googlegroups.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-sql@postgresql.org
  Cc: 99m@myway.com
  Subject: Re: Tough Problem -- Record Checkouts
  In-Reply-To: <1139851981.176833.302970@g43g2000cwa.googlegroups.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