Re: deleting records is failing

From: Michael Glaesemann <grzm(at)myrealbox(dot)com>
To: "Tim Vadnais" <tvadnais(at)earthlink(dot)net>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: deleting records is failing
Date: 2005-12-08 04:27:39
Message-ID: 7A278D8C-3A76-4256-AA13-61373BF12820@myrealbox.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On Dec 8, 2005, at 13:01 , Tim Vadnais wrote:

> Thank you.
>
> I've modified the code to read:
>
> DELETE from tracker WHERE tracker.episode_id = 277 AND
> tracker.date_of_service BETWEEN '09/12/2005'::date - interval '1
> day' AND
> '10/20/2005'::date + interval '1 day'

If you're going to be doing a lot of this, you might want to wrap it
in a simple SQL function, such as :

create or replace function oo_between (
date -- date to check
, date -- start date of interval
, date -- end date of interval
) returns boolean
strict
immutable
language sql as $$
select $1 > $2 and $1 < $3;
$$;

Untested, and check the direction of the inequalities. I always seem
to screw that up. I chose the oo_ prefix because this is sometimes
called an open-open interval. BETWEEN on the other hand tests a
closed-closed interval.

You can call it like this:

DELETE FROM tracker
WHERE episode_id = 227
AND oo_between(date_of_service, '2005-09-12'::date, '2005-10-20'::date);

Michael Glaesemann
grzm myrealbox com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Kathy Lo 2005-12-08 04:29:11 Re: memory leak under heavy load?
Previous Message John DeSoi 2005-12-08 04:21:48 Re: php from windowsXP box