Problem with zero year

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: PostgreSQL-development <pgsql-hackers(at)postgreSQL(dot)org>
Subject: Problem with zero year
Date: 2009-03-17 14:57:52
Message-ID: 200903171457.n2HEvqJ20005@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

We added the following commit in 8.4:

/src/backend/utils/adt/datetime.c
tgl
Reject year zero during datetime input, except when it's a 2-digit
year (then it means 2000 AD). Formerly we silently interpreted this
as 1 BC, which at best is unwarranted familiarity with the implementation.
It's barely possible that some app somewhere expects the old behavior,
though, so we won't back-patch this into existing release branches.

The problem is that the 2-digit year check is for <=2 digits, not
exactly two digits:

/*
* When processing a year field, mark it for adjustment if it's only one
* or two digits.
*/
if (*tmask == DTK_M(YEAR))
*is2digits = (flen <= 2);

This leads to some unexpected outputs:

test=> select '1-1-0'::date;
date
------------
2000-01-01

test=> select '1-1-0 BC'::date;
ERROR: date/time field value out of range: "1-1-0 BC"
LINE 1: select '1-1-0 BC'::date;
^

test=> select '1-1-0 AD'::date;
date
------------
2000-01-01

test=> select '1-1-000'::date;
ERROR: date/time field value out of range: "1-1-000"
LINE 1: select '1-1-000'::date;

I think the BC part is fine because that can't possibily be 2000 AD, but
having '0' interpreted as 2000 seems counter to the commit message text;
should the assignment be changed to:

if (*tmask == DTK_M(YEAR))
*is2digits = (flen == 2);

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2009-03-17 15:15:21 Re: small but useful patches for text search
Previous Message Zdenek Kotala 2009-03-17 13:49:06 Re: DTrace probes broken in HEAD on Solaris?