Re: question using 'between' in a sql query

From: Theodore Petrosky <tedpet5(at)yahoo(dot)com>
To: Michael Fuhr <mike(at)fuhr(dot)org>
Cc: postgres SQL <pgsql-sql(at)postgresql(dot)org>
Subject: Re: question using 'between' in a sql query
Date: 2005-12-04 16:28:54
Message-ID: 20051204162854.79878.qmail@web31701.mail.mud.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

thanks... as is so often the case I discovered

date_trunc('day', insertdate) between '11/20/2005' AND
'11/20/2005' also works....

It wasn't until I pressed the send button that I
thought of the solution. I have thought of creating a
faux 'send' button for my email software... yours is a
little easier to read (human)..

Thanks again,

Ted

--- Michael Fuhr <mike(at)fuhr(dot)org> wrote:

> On Sat, Dec 03, 2005 at 09:54:16AM -0800, Theodore
> Petrosky wrote:
> > if 'between' is inclusive of the start and end
> dates why doesn't
> > this query result in all the rows on '11/20/2005'?
>
> EXPLAIN shows what happens when you compare a date
> against a timestamp:
>
> Filter: ((insertdate >= '2005-11-20
> 00:00:00-08'::timestamp with time zone)
> AND (insertdate <= '2005-11-20
> 00:00:00-08'::timestamp with time zone))
>
> One way around this is to cast the timestamp column
> to date:
>
> SELECT employeecode
> FROM mytable
> WHERE insertdate::date BETWEEN '11/20/2005' AND
> '11/20/2005';
>
> --
> Michael Fuhr
>


__________________________________
Start your day with Yahoo! - Make it your home page!
http://www.yahoo.com/r/hs

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Joost Kraaijeveld 2005-12-04 21:12:52 How to get a count() where column < ''?
Previous Message Andreas Kretschmer 2005-12-04 13:36:09 Re: SQL Statement Help needed