Re: New to_timestamp implementation is pretty strict

From: Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Greg Stark <stark(at)enterprisedb(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Dave Page <dpage(at)pgadmin(dot)org>, "David E(dot) Wheeler" <david(at)kineticode(dot)com>, Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: New to_timestamp implementation is pretty strict
Date: 2008-12-01 18:46:41
Message-ID: 49343111.8070300@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Robert Haas wrote:
> On Mon, Dec 1, 2008 at 10:33 AM, Greg Stark <stark(at)enterprisedb(dot)com> wrote:
>> How would you parse an input format of just 'SS' ? is there something
>> ambiguous about '3' ? I don't see anything "bad" about using %d to
>> output an integer number of seconds.
>
> +1.
>
> It seems to me that it's pretty silly to say that we "know" that the 2
> in "01:2:03" is intended to mean 02, but we are somehow confused about
> whether the 3 in "01:02:3" is intended to mean 03 or 30.

Yep. It's a fair argument that we shouldn't accept either, but the
inconsistency is just wrong. I've committed a patch fixing the
inconsistency, by allowing "01:02:3".

Now whether we should forbid both, my opinion is that we shouldn't; that
would just unnecessarily brake old applications, and I don't think
there's much danger of ambiguity in what "01:2:03" means.

For better or worse, we also allow these more questionable inputs:

postgres=# SELECT to_timestamp('2008/-3/01', 'YYYY/MM/DD');
to_timestamp
------------------------
2007-09-01 00:00:00+03
(1 row)

postgres=# SELECT to_timestamp('2008--3-01', 'YYYY-MM-DD');
to_timestamp
------------------------
2007-09-01 00:00:00+03
(1 row)

postgres=# SELECT to_timestamp('2008-03', 'YYYY-MM-DD');
to_timestamp
------------------------
2008-03-01 00:00:00+02
(1 row)

postgres=# SELECT to_timestamp('2008-03-04-foobar', 'YYYY-MM-DD');
to_timestamp
------------------------
2008-03-04 00:00:00+02
(1 row)

The argument for rejecting these is stronger, IMHO, but given that we
allowed these in previous releases as well, I don't think we try to
forbid them either.

--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2008-12-01 19:00:50 Re: New to_timestamp implementation is pretty strict
Previous Message Vignesh Raaj 2008-12-01 18:39:23 Reg: Nested query