pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: amul sul <sul_amul@yahoo.co.in>
To: Robert Haas <robertmhaas@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: PostgreSQL-development <pgsql-hackers@postgresql.org>
Subject: Re: Bug in to_timestamp().
Date: Wed, 15 Jun 2016 09:33:41 +0000 (UTC)
Message-ID: <417387085.2692378.1465983221272.JavaMail.yahoo@mail.yahoo.com> (raw)
In-Reply-To: <CA+TgmoaD8TuS=sHKS1f1qAfizCBouejgmO2jYnJ_=ia343uGSA@mail.gmail.com>
References: <1873520224.1784572.1465833145330.JavaMail.yahoo.ref@mail.yahoo.com>
	<1873520224.1784572.1465833145330.JavaMail.yahoo@mail.yahoo.com>
	<20932.1465834344@sss.pgh.pa.us>
	<CA+TgmoaD8TuS=sHKS1f1qAfizCBouejgmO2jYnJ_=ia343uGSA@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>

On Monday, 13 June 2016 9:57 PM, Robert Haas <robertmhaas@gmail.com> wrote:


>I think a space in the format string should skip a whitespace
>character in the input string, but not a non-whitespace character.

+1, enough the benefit is we are giving correct output. 
 
PFA patch proposing this fix.

Regards,
Amul Sul. 

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

Attachments:

0001-RM37358-space-in-the-format-string-should-skip-a-whi.patch (application/octet-stream, 4.3K) download From e79001a912c9b8bfbcd5eef24fca61f4ac08becb Mon Sep 17 00:00:00 2001 From: Amul Sul <sul_amul@yahoo.co.in> Date: Wed, 15 Jun 2016 14:42:43 +0530 Subject: [PATCH] RM37358: space in the format string should skip a whitespace in input --- src/backend/utils/adt/formatting.c | 20 ++++++++++++++++---- src/test/regress/expected/horology.out | 12 ++++++------ src/test/regress/sql/horology.sql | 4 ++-- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/backend/utils/adt/formatting.c b/src/backend/utils/adt/formatting.c index ae93fe0..ccacc09 100644 --- a/src/backend/utils/adt/formatting.c +++ b/src/backend/utils/adt/formatting.c @@ -2955,11 +2955,23 @@ DCH_from_char(FormatNode *node, char *in, TmFromChar *out) if (n->type != NODE_TYPE_ACTION) { /* - * Separator, so consume one character from input string. Notice - * we don't insist that the consumed character match the format's - * character. + * Ignore spaces when not in FX (fixed width) mode and space in + * the format string. */ - s++; + if (!fx_mode && isspace((unsigned char) n->character)) + { + while (*s != '\0' && isspace((unsigned char) *s)) + s++; + } + else + { + /* + * Separator, so consume one character from input string. + * Notice we don't insist that the consumed character match + * the format's character. + */ + s++; + } continue; } diff --git a/src/test/regress/expected/horology.out b/src/test/regress/expected/horology.out index 1fe02be..98a9681 100644 --- a/src/test/regress/expected/horology.out +++ b/src/test/regress/expected/horology.out @@ -2776,7 +2776,7 @@ SELECT to_timestamp('1985 January 12', 'YYYY FMMonth DD'); (1 row) SELECT to_timestamp('My birthday-> Year: 1976, Month: May, Day: 16', - '"My birthday-> Year" YYYY, "Month:" FMMonth, "Day:" DD'); + '"My birthday-> Year:" YYYY, "Month:" FMMonth, "Day:" DD'); to_timestamp ------------------------------ Sun May 16 00:00:00 1976 PDT @@ -2789,7 +2789,7 @@ SELECT to_timestamp('1,582nd VIII 21', 'Y,YYYth FMRM DD'); (1 row) SELECT to_timestamp('15 "text between quote marks" 98 54 45', - E'HH24 "\\text between quote marks\\"" YY MI SS'); + E'HH24 "\\"text between quote marks\\"" YY MI SS'); to_timestamp ------------------------------ Thu Jan 01 15:54:45 1998 PST @@ -2912,7 +2912,7 @@ SELECT to_timestamp(' 20050302', 'YYYYMMDD'); SELECT to_timestamp('2011-12-18 23:38:15', 'YYYY-MM-DD HH24:MI:SS'); to_timestamp ------------------------------ - Sun Dec 18 03:38:15 2011 PST + Sun Dec 18 23:38:15 2011 PST (1 row) SELECT to_timestamp('2011-12-18 23:38:15', 'YYYY-MM-DD HH24:MI:SS'); @@ -2942,7 +2942,7 @@ SELECT to_timestamp('2011-12-18 23:38:15', 'YYYY-MM-DD HH24:MI:SS'); SELECT to_timestamp('2011-12-18 23:38:15', 'YYYY-MM-DD HH24:MI:SS'); to_timestamp ------------------------------ - Sun Dec 18 03:38:15 2011 PST + Sun Dec 18 23:38:15 2011 PST (1 row) SELECT to_date('2011 12 18', 'YYYY MM DD'); @@ -2960,13 +2960,13 @@ SELECT to_date('2011 12 18', 'YYYY MM DD'); SELECT to_date('2011 12 18', 'YYYY MM DD'); to_date ------------ - 12-08-2011 + 12-18-2011 (1 row) SELECT to_date('2011 12 18', 'YYYY MM DD'); to_date ------------ - 02-18-2011 + 12-18-2011 (1 row) SELECT to_date('2011 12 18', 'YYYY MM DD'); diff --git a/src/test/regress/sql/horology.sql b/src/test/regress/sql/horology.sql index c81437b..71f0acf 100644 --- a/src/test/regress/sql/horology.sql +++ b/src/test/regress/sql/horology.sql @@ -395,12 +395,12 @@ SELECT to_timestamp('97/2/16 8:14:30', 'FMYYYY/FMMM/FMDD FMHH:FMMI:FMSS'); SELECT to_timestamp('1985 January 12', 'YYYY FMMonth DD'); SELECT to_timestamp('My birthday-> Year: 1976, Month: May, Day: 16', - '"My birthday-> Year" YYYY, "Month:" FMMonth, "Day:" DD'); + '"My birthday-> Year:" YYYY, "Month:" FMMonth, "Day:" DD'); SELECT to_timestamp('1,582nd VIII 21', 'Y,YYYth FMRM DD'); SELECT to_timestamp('15 "text between quote marks" 98 54 45', - E'HH24 "\\text between quote marks\\"" YY MI SS'); + E'HH24 "\\"text between quote marks\\"" YY MI SS'); SELECT to_timestamp('05121445482000', 'MMDDHH24MISSYYYY'); -- 2.6.2

view thread (138+ messages)  latest in thread

Message-ID: <417387085.2692378.1465983221272.JavaMail.yahoo@mail.yahoo.com>
Permalink:  ../417387085.2692378.1465983221272.JavaMail.yahoo@mail.yahoo.com/
Also on:    postgresql.org/message-id/417387085.2692378.1465983221272.JavaMail.yahoo@mail.yahoo.com

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: sul_amul@yahoo.co.in, robertmhaas@gmail.com, tgl@sss.pgh.pa.us
  Subject: Re: Bug in to_timestamp().
  In-Reply-To: <417387085.2692378.1465983221272.JavaMail.yahoo@mail.yahoo.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox