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  <br...@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

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

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to