Re: search for partial dates

From: Christophe <xof(at)thebuild(dot)com>
To: PostgreSQL general <pgsql-general(at)postgresql(dot)org>
Subject: Re: search for partial dates
Date: 2009-06-11 20:30:15
Message-ID: 6FFF18D5-00D8-4015-ACA5-9D01F82C3DC9@thebuild.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On Jun 11, 2009, at 1:23 PM, James B. Byrne wrote:

> Given a datetime column, not null, is there a single syntax that
> permits searching for all dates in a given year, year+month, and
> year+month+day such that a single parameterised query can handle all
> three circumstances?

Well, of course, in a trivial sense:

SELECT * FROM the_table WHERE datetimecolumn >= $1 AND datetimecolumn
<= $2;

The application has to create the appropriate values for the first and
last days of the year or month in this case, but it's a rare language
that doesn't that facility.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2009-06-11 20:35:20 Re: search for partial dates
Previous Message James B. Byrne 2009-06-11 20:23:30 search for partial dates