This is my first template

Lists: pgsql-general
From: Geoff Caplan <geoff(at)uviva(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: This is my first template
Date: 2009-04-21 11:02:02
Message-ID: 200904211103.n3LB329b023342@rs48.luxsci.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Hi folks

Looks like there's something I'm not understanding about
date/time queries on a date field.

I have a param query that includes the statement:

AND active_from_date <= $2

where $2 is a well-formed ISO date.

Query works as expected when there are records in the result
set. When the result set is empty, PG throws an error:

date/time field value out of range: "2011-4-31"

I'm using the default datestyle setting, which should work
here, I think? Experimenting with other settings hasn't helped.

This query runs hundreds of times a day and I don't want the
error clogging up my logs. But I don't want to suppress the
error as the query is business-critical and I need to know
if anything goes wrong.

I'd welcome suggestions as to how I can get this query to
run without throwing a date/time error when the result set
is empty.

Thanks...

--
Geoff Caplan
Uviva Ltd

Attachment Content-Type Size
geoff.vcf text/x-vcard 233 bytes

From: Sam Mason <sam(at)samason(dot)me(dot)uk>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: This is my first template
Date: 2009-04-21 11:34:03
Message-ID: 20090421113403.GI12225@frubble.xen.chris-lamb.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On Tue, Apr 21, 2009 at 12:02:02PM +0100, Geoff Caplan wrote:
> Looks like there's something I'm not understanding about
> date/time queries on a date field.

[...]

> date/time field value out of range: "2011-4-31"

As far as I'm aware; April only has 30 days. You're asking PG for an
invalid date and this is its way of telling you so!

--
Sam http://samason.me.uk/


From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: Geoff Caplan <geoff(at)uviva(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: This is my first template
Date: 2009-04-21 11:34:11
Message-ID: b42b73150904210434m70ffa1fbhcc3c351b142efcd4@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On Tue, Apr 21, 2009 at 7:02 AM, Geoff Caplan <geoff(at)uviva(dot)com> wrote:
> Hi folks
>
> Looks like there's something I'm not understanding about date/time queries
> on a date field.
>
> I have a param query that includes the statement:
>
> AND active_from_date <= $2
>
> where $2 is a well-formed ISO date.
>
> Query works as expected when there are records in the result set. When the
> result set is empty, PG throws an error:
>
> date/time field value out of range: "2011-4-31"

"2011-4-31" is not a well formed ISO date.

merlin


From: milos(dot)babic(at)gmail(dot)com
To: Merlin Moncure <mmoncure(at)gmail(dot)com>, Geoff Caplan <geoff(at)uviva(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: This is my first template
Date: 2009-04-21 11:38:39
Message-ID: 001636416c7798ecc004680f1620@google.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

There are 30 days in April.

On Apr 21, 2009 2:34pm, Merlin Moncure <mmoncure(at)gmail(dot)com> wrote:
> On Tue, Apr 21, 2009 at 7:02 AM, Geoff Caplan geoff(at)uviva(dot)com> wrote:

> > Hi folks

> >

> > Looks like there's something I'm not understanding about date/time
> queries

> > on a date field.

> >

> > I have a param query that includes the statement:

> >

> > AND active_from_date
> >

> > where $2 is a well-formed ISO date.

> >

> > Query works as expected when there are records in the result set. When
> the

> > result set is empty, PG throws an error:

> >

> > date/time field value out of range: "2011-4-31"

> "2011-4-31" is not a well formed ISO date.

> merlin

> --

> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)

> To make changes to your subscription:

> http://www.postgresql.org/mailpref/pgsql-general


From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Geoff Caplan <geoff(at)uviva(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: This is my first template
Date: 2009-04-21 14:29:29
Message-ID: 20090421142929.GN10358@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Geoff Caplan wrote:

> where $2 is a well-formed ISO date.
>
> Query works as expected when there are records in the result set. When
> the result set is empty, PG throws an error:
>
> date/time field value out of range: "2011-4-31"

Is April 31st really a well-formed ISO date? I wonder what jhey smoke
there in ISO meetings.

My guess is that you're doing date arithmetic wrong somewhere.

--
Alvaro Herrera http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.