Re: timestamptz parsing bug?

Lists: pgsql-hackers
From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: timestamptz parsing bug?
Date: 2011-08-29 14:40:58
Message-ID: 4E5BA4FA.6080801@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


Why do we parse this as a correct timestamptz literal:

2011-08-29T09:11:14.123 CDT

but not this:

2011-08-29T09:11:14.123 America/Chicago

Replace the ISO-8601 style T between the date and time parts of the
latter with a space and the parser is happy again.

cheers

andrew


From: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: timestamptz parsing bug?
Date: 2011-08-29 17:40:07
Message-ID: CAEZATCX893NNUzhtBz7-+SA3mLLNrbV5M4s1twygV86Zu6nX5g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 29 August 2011 15:40, Andrew Dunstan <andrew(at)dunslane(dot)net> wrote:
>
> Why do we parse this as a correct timestamptz literal:
>
>    2011-08-29T09:11:14.123 CDT
>
> but not this:
>
>    2011-08-29T09:11:14.123 America/Chicago
>
> Replace the ISO-8601 style T between the date and time parts of the latter
> with a space and the parser is happy again.
>
>
> cheers
>
> andrew
>

Funny, I've just recently been looking at this code.

I think that the issue is in the DTK_TIME handling code in DecodeDateTime().

For this input string the "T" is recognised as the start of an ISO
time, and the ptype variable is set to DTK_TIME. The next field is a
DTK_TIME, however, when it is handled it doesn't reset the ptype
variable.

When it gets to the timezone "America/Chicago" at the end, this is
handled in the DTK_DATE case, because of the "/". But because ptype is
still set, it is expecting this to be an ISO time, so it errors out.

The attached patch seems to fix it. Could probably use a new
regression test though.

Regards,
Dean

Attachment Content-Type Size
datetime.patch application/octet-stream 690 bytes

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
Cc: Andrew Dunstan <andrew(at)dunslane(dot)net>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: timestamptz parsing bug?
Date: 2011-08-29 19:30:02
Message-ID: 10516.1314646202@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com> writes:
> On 29 August 2011 15:40, Andrew Dunstan <andrew(at)dunslane(dot)net> wrote:
>> Why do we parse this as a correct timestamptz literal:
>> 2011-08-29T09:11:14.123 CDT
>> but not this:
>> 2011-08-29T09:11:14.123 America/Chicago

> For this input string the "T" is recognised as the start of an ISO
> time, and the ptype variable is set to DTK_TIME. The next field is a
> DTK_TIME, however, when it is handled it doesn't reset the ptype
> variable.

> When it gets to the timezone "America/Chicago" at the end, this is
> handled in the DTK_DATE case, because of the "/". But because ptype is
> still set, it is expecting this to be an ISO time, so it errors out.

Do we actually *want* to support this? The "T" is supposed to mean that
the string is strictly ISO-conformant, no?

regards, tom lane


From: "David E(dot) Wheeler" <david(at)kineticode(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: timestamptz parsing bug?
Date: 2011-08-29 19:35:25
Message-ID: 56ACB5A7-DAEB-431B-91E3-10CAC6F8F2BF@kineticode.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Aug 29, 2011, at 12:30 PM, Tom Lane wrote:

>> When it gets to the timezone "America/Chicago" at the end, this is
>> handled in the DTK_DATE case, because of the "/". But because ptype is
>> still set, it is expecting this to be an ISO time, so it errors out.
>
> Do we actually *want* to support this? The "T" is supposed to mean that
> the string is strictly ISO-conformant, no?

I didn't realize that appending a time zone was not conformant, but apparently it's not.

http://en.wikipedia.org/wiki/ISO_8601#Time_zone_designators

Only appending a "Z" or an offset seems to be legal. Interesting.

David


From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: "David E(dot) Wheeler" <david(at)kineticode(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: timestamptz parsing bug?
Date: 2011-08-29 19:43:57
Message-ID: 4E5BEBFD.4090800@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 08/29/2011 03:35 PM, David E. Wheeler wrote:
> On Aug 29, 2011, at 12:30 PM, Tom Lane wrote:
>
>>> When it gets to the timezone "America/Chicago" at the end, this is
>>> handled in the DTK_DATE case, because of the "/". But because ptype is
>>> still set, it is expecting this to be an ISO time, so it errors out.
>> Do we actually *want* to support this? The "T" is supposed to mean that
>> the string is strictly ISO-conformant, no?
> I didn't realize that appending a time zone was not conformant, but apparently it's not.
>
> http://en.wikipedia.org/wiki/ISO_8601#Time_zone_designators
>
> Only appending a "Z" or an offset seems to be legal. Interesting.
>
>

In that case we shouldn't be accepting an abbreviation either.

cheers

andrew


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: "David E(dot) Wheeler" <david(at)kineticode(dot)com>, Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: timestamptz parsing bug?
Date: 2011-08-29 20:29:39
Message-ID: 24669.1314649779@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Andrew Dunstan <andrew(at)dunslane(dot)net> writes:
> On 08/29/2011 03:35 PM, David E. Wheeler wrote:
>> On Aug 29, 2011, at 12:30 PM, Tom Lane wrote:
>>> Do we actually *want* to support this? The "T" is supposed to mean that
>>> the string is strictly ISO-conformant, no?

> In that case we shouldn't be accepting an abbreviation either.

Yeah, that would be the logical conclusion. OTOH you could argue that
we don't want to remove the abbreviation case for backward-compatibility
reasons, in which case allowing full names as well is a reasonable
thing. I don't know the answer, I'm just asking the question.

regards, tom lane


From: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: "David E(dot) Wheeler" <david(at)kineticode(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: timestamptz parsing bug?
Date: 2011-08-29 20:31:00
Message-ID: CAEZATCUcrfpRq_hBwxgteDmjWkP_29QwjOB572t-CTXfgJtYVQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 29 August 2011 20:43, Andrew Dunstan <andrew(at)dunslane(dot)net> wrote:
>
>
> On 08/29/2011 03:35 PM, David E. Wheeler wrote:
>>
>> On Aug 29, 2011, at 12:30 PM, Tom Lane wrote:
>>
>>>> When it gets to the timezone "America/Chicago" at the end, this is
>>>> handled in the DTK_DATE case, because of the "/". But because ptype is
>>>> still set, it is expecting this to be an ISO time, so it errors out.
>>>
>>> Do we actually *want* to support this?  The "T" is supposed to mean that
>>> the string is strictly ISO-conformant, no?
>>
>> I didn't realize that appending a time zone was not conformant, but
>> apparently it's not.
>>
>>   http://en.wikipedia.org/wiki/ISO_8601#Time_zone_designators
>>
>> Only appending a "Z" or an offset seems to be legal. Interesting.
>>
>>
>
> In that case we shouldn't be accepting an abbreviation either.
>

The remit of the function is to support inputs in "almost any
reasonable format", not just ISO format. I'd say that supporting both
extensions of the ISO format is reasonable. Supporting one and not the
other is inconsistent, and removing support for one will likely break
someone's code.

Regards,
Dean


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
Cc: Andrew Dunstan <andrew(at)dunslane(dot)net>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: timestamptz parsing bug?
Date: 2012-08-15 21:29:26
Message-ID: 20120815212926.GP25473@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


I assume we want to apply this patch based on discussion that we should
allow a wider range of date/time formats.

---------------------------------------------------------------------------

On Mon, Aug 29, 2011 at 06:40:07PM +0100, Dean Rasheed wrote:
> On 29 August 2011 15:40, Andrew Dunstan <andrew(at)dunslane(dot)net> wrote:
> >
> > Why do we parse this as a correct timestamptz literal:
> >
> >    2011-08-29T09:11:14.123 CDT
> >
> > but not this:
> >
> >    2011-08-29T09:11:14.123 America/Chicago
> >
> > Replace the ISO-8601 style T between the date and time parts of the latter
> > with a space and the parser is happy again.
> >
> >
> > cheers
> >
> > andrew
> >
>
> Funny, I've just recently been looking at this code.
>
> I think that the issue is in the DTK_TIME handling code in DecodeDateTime().
>
> For this input string the "T" is recognised as the start of an ISO
> time, and the ptype variable is set to DTK_TIME. The next field is a
> DTK_TIME, however, when it is handled it doesn't reset the ptype
> variable.
>
> When it gets to the timezone "America/Chicago" at the end, this is
> handled in the DTK_DATE case, because of the "/". But because ptype is
> still set, it is expecting this to be an ISO time, so it errors out.
>
> The attached patch seems to fix it. Could probably use a new
> regression test though.
>
> Regards,
> Dean

> diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
> new file mode 100644
> index 3d320cc..a935d98
> *** a/src/backend/utils/adt/datetime.c
> --- b/src/backend/utils/adt/datetime.c
> *************** DecodeDateTime(char **field, int *ftype,
> *** 942,947 ****
> --- 942,957 ----
> break;
>
> case DTK_TIME:
> + /*
> + * This might be an ISO time following a "t" field.
> + */
> + if (ptype != 0)
> + {
> + /* Sanity check; should not fail this test */
> + if (ptype != DTK_TIME)
> + return DTERR_BAD_FORMAT;
> + ptype = 0;
> + }
> dterr = DecodeTime(field[i], fmask, INTERVAL_FULL_RANGE,
> &tmask, tm, fsec);
> if (dterr)

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

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

+ It's impossible for everything to be true. +


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
Cc: Andrew Dunstan <andrew(at)dunslane(dot)net>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: timestamptz parsing bug?
Date: 2012-08-25 21:45:10
Message-ID: 20120825214509.GD10814@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, Aug 15, 2012 at 05:29:26PM -0400, Bruce Momjian wrote:
>
> I assume we want to apply this patch based on discussion that we should
> allow a wider range of date/time formats.

Applied, thanks.

---------------------------------------------------------------------------

>
> On Mon, Aug 29, 2011 at 06:40:07PM +0100, Dean Rasheed wrote:
> > On 29 August 2011 15:40, Andrew Dunstan <andrew(at)dunslane(dot)net> wrote:
> > >
> > > Why do we parse this as a correct timestamptz literal:
> > >
> > >    2011-08-29T09:11:14.123 CDT
> > >
> > > but not this:
> > >
> > >    2011-08-29T09:11:14.123 America/Chicago
> > >
> > > Replace the ISO-8601 style T between the date and time parts of the latter
> > > with a space and the parser is happy again.
> > >
> > >
> > > cheers
> > >
> > > andrew
> > >
> >
> > Funny, I've just recently been looking at this code.
> >
> > I think that the issue is in the DTK_TIME handling code in DecodeDateTime().
> >
> > For this input string the "T" is recognised as the start of an ISO
> > time, and the ptype variable is set to DTK_TIME. The next field is a
> > DTK_TIME, however, when it is handled it doesn't reset the ptype
> > variable.
> >
> > When it gets to the timezone "America/Chicago" at the end, this is
> > handled in the DTK_DATE case, because of the "/". But because ptype is
> > still set, it is expecting this to be an ISO time, so it errors out.
> >
> > The attached patch seems to fix it. Could probably use a new
> > regression test though.
> >
> > Regards,
> > Dean
>
> > diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
> > new file mode 100644
> > index 3d320cc..a935d98
> > *** a/src/backend/utils/adt/datetime.c
> > --- b/src/backend/utils/adt/datetime.c
> > *************** DecodeDateTime(char **field, int *ftype,
> > *** 942,947 ****
> > --- 942,957 ----
> > break;
> >
> > case DTK_TIME:
> > + /*
> > + * This might be an ISO time following a "t" field.
> > + */
> > + if (ptype != 0)
> > + {
> > + /* Sanity check; should not fail this test */
> > + if (ptype != DTK_TIME)
> > + return DTERR_BAD_FORMAT;
> > + ptype = 0;
> > + }
> > dterr = DecodeTime(field[i], fmask, INTERVAL_FULL_RANGE,
> > &tmask, tm, fsec);
> > if (dterr)
>
> >
> > --
> > Sent via pgsql-hackers mailing list (pgsql-hackers(at)postgresql(dot)org)
> > To make changes to your subscription:
> > http://www.postgresql.org/mailpref/pgsql-hackers
>
>
> --
> Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
> EnterpriseDB http://enterprisedb.com
>
> + It's impossible for everything to be true. +
>
>
> --
> Sent via pgsql-hackers mailing list (pgsql-hackers(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-hackers

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

+ It's impossible for everything to be true. +