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 0325B9DCBD7 for ; Sat, 3 Dec 2005 14:15:24 -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 10298-04 for ; Sat, 3 Dec 2005 14:15:20 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by postgresql.org (Postfix) with ESMTP id EDB2C9DCBD6 for ; Sat, 3 Dec 2005 14:15:20 -0400 (AST) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id jB3IFGU5071884 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sat, 3 Dec 2005 11:15:19 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.4/8.13.4) with ESMTP id jB3IFGsW012778; Sat, 3 Dec 2005 11:15:16 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.4/8.13.4/Submit) id jB3IFGFU012777; Sat, 3 Dec 2005 11:15:16 -0700 (MST) (envelope-from mfuhr) Date: Sat, 3 Dec 2005 11:15:15 -0700 From: Michael Fuhr To: Theodore Petrosky Cc: postgres SQL Subject: Re: question using 'between' in a sql query Message-ID: <20051203181515.GA12719@winnie.fuhr.org> References: <20051203175416.31456.qmail@web31712.mail.mud.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20051203175416.31456.qmail@web31712.mail.mud.yahoo.com> 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: 200512/13 X-Sequence-Number: 23555 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