Re: search for partial dates

From: "Leif B(dot) Kristensen" <leif(at)solumslekt(dot)org>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: search for partial dates
Date: 2009-06-11 22:47:26
Message-ID: 200906120047.26529.leif@solumslekt.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thursday 11. June 2009, 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?

Apart from the other excellent replies you've got, you can always do
some explicit casting and produce interesting things like:

CREATE OR REPLACE FUNCTION date2text(DATE) RETURNS TEXT AS $$
-- removes hyphens from a regular date
SELECT
SUBSTR(TEXT($1),1,4) ||
SUBSTR(TEXT($1),6,2) ||
SUBSTR(TEXT($1),9,2)
$$ LANGUAGE sql STABLE;

for example.
--
Leif Biberg Kristensen | Registered Linux User #338009
Me And My Database: http://solumslekt.org/blog/

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message suylivar 2009-06-12 03:10:03 PostgreSQL installation
Previous Message Leif B. Kristensen 2009-06-11 22:31:12 Re: When to use cascading deletes?