Re: search for partial dates

From: Andy Colson <andy(at)squeakycode(dot)net>
To: "James B(dot) Byrne" <byrnejb(at)harte-lyne(dot)ca>
Subject: Re: search for partial dates
Date: 2009-06-11 21:37:28
Message-ID: 4A317918.7050105@squeakycode.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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?
>

That's a little vague, so how about:

select * from somethine where (extract(year from idate) = $1) or
(extract(year from idate) = $2 and extract(month from idate) = $3) or
(extract(year from idate) = $4 and extract(month from idate) = $5 and
extract(day from idate) = $6)

-Andy

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alvaro Herrera 2009-06-11 22:10:04 Re: Postgres auditing features
Previous Message Scott Marlowe 2009-06-11 21:27:56 Re: help with data recovery from injected UPDATE