Re: Meridiem markers (was: [BUGS] Incorrect "invalid AM/PM string" error from to_timestamp)

From: "Brendan Jurd" <direvus(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Cc: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Alex Hunsaker" <badalex(at)gmail(dot)com>
Subject: Re: Meridiem markers (was: [BUGS] Incorrect "invalid AM/PM string" error from to_timestamp)
Date: 2009-01-19 22:26:27
Message-ID: 37ed240d0901191426o545674des75b75d94dd1b75ac@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sat, Sep 27, 2008 at 4:25 AM, Brendan Jurd <direvus(at)gmail(dot)com> wrote:
> One way to tidy this up would be to re-implement the meridiem markers
> using the seq_search functions, i.e., make it work like the day and
> month names. This would make it easy to accept any flavour of marker,
> and the error messages thrown for bogus input would then be the same
> as those for bogus day and month names.
>

From the better-late-than-never department, comes a patch to improve
the handling of AM/PM and AD/BC markers in to_timestamp(), and up the
ante on error reporting for various kinds of invalid input.

The only difference as far as parsing goes is that we no longer worry
about the case of AM/PM and AD/BC. As long as you use the right
variation for with/without periods, it will parse.

Internally, the code now uses seq_search to parse the markers, so they
work in much the same way as month and day names do.

I improved the error messages for when a seq_search fails, and when
the code fails to parse an integer. Some examples of the new error
messages:

postgres=# select to_timestamp('Tue 20 Foo 2009 11:39 PM', 'Dy DD Mon
YYYY HH:MI PM');
ERROR: invalid value "Foo" for "Mon"
DETAIL: The given value did not match any of the allowed values for this field.

postgres=# select to_timestamp('Tue 20 Jan 2009 11:39 pn', 'Dy DD Mon
YYYY HH:MI PM');
ERROR: invalid value "PN" for "PM"
DETAIL: The given value did not match any of the allowed values for this field.

postgres=# select to_timestamp('Tue 20 Jan 2009 23:39', 'Dy DD Mon YYYY HH:MI');
ERROR: hour "23" is invalid for the 12-hour clock
HINT: Use the 24-hour clock, or give an hour between 1 and 12.

postgres=# select to_timestamp('Tue 20 Jan 2009 xx:39 pm', 'Dy DD Mon
YYYY HH:MI PM');
ERROR: invalid value "xx" for "HH"
DETAIL: Value must be an integer.

This resolves TODO item "Improve to_timestamp() handling of AM/PM, and
error messages". I've added the patch to the 2009 commitfest.

Cheers,
BJ

doc/src/sgml/func.sgml | 24 +--
src/backend/utils/adt/formatting.c | 235 ++++++++++++++++-----------------
src/test/regress/expected/horology.out | 10 -
src/test/regress/sql/horology.sql | 4
4 files changed, 137 insertions(+), 136 deletions(-)

Attachment Content-Type Size
ampm-seqsearch.diff.bz2 application/x-bzip2 5.5 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2009-01-19 22:55:55 Re: Statement-level triggers and inheritance
Previous Message Todd A. Cook 2009-01-19 21:22:21 is 8.4 array_agg() supposed to work with array values?