pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
Cc: Robert Haas <robertmhaas@gmail.com>
Cc: Andreas 'ads' Scherbaum <adsmail@wars-nicht.de>
Cc: Artur Zakirov <a.zakirov@postgrespro.ru>
Cc: Joshua D. Drake <jd@commandprompt.com>
Cc: Albe Laurenz <laurenz.albe@wien.gv.at>
Cc: 'Andreas Karlsson *EXTERN*' <andreas@proxel.se>
Cc: Pavel Stehule <pavel.stehule@gmail.com>
Cc: Jaime Casanova <jaime.casanova@2ndquadrant.com>
Cc: Euler Taveira <euler@timbira.com.br>
Cc: Pg Hackers <pgsql-hackers@postgresql.org>
Subject: Re: to_date_valid()
Date: Tue, 27 Sep 2016 17:01:03 -0400
Message-ID: <2284.1475010063@sss.pgh.pa.us> (raw)
In-Reply-To: <7fde7a91-0ad3-33ac-c348-cf58e4638464@2ndquadrant.com>
References: <57786490.9010201@wars-nicht.de>
	<dcdebc73-ffdd-13a3-d6cd-73e1944a066b@timbira.com.br>
	<CAJGNTeO75ZPm3qDk9rze7coGyvCZyWm68iEFY3WOYb5w=7OdBg@mail.gmail.com>
	<5778EA94.1020706@wars-nicht.de>
	<af97b147-3542-7a55-b651-e0ecae0c8c00@proxel.se>
	<CAFj8pRDHaeVdwHtZQPXKCSaeAQ_2_jeXHpPCssiOdFYs7UoUTw@mail.gmail.com>
	<2bc6bcef-cada-1ac7-f9a2-2f6128ca4c3c@proxel.se>
	<A737B7A37273E048B164557ADEF4A58B5386992E@ntex2010i.host.magwien.gv.at>
	<b28373f4-7e37-3bc4-25a5-65aef4006cf0@2ndquadrant.com>
	<579823DF.3080903@commandprompt.com>
	<e9617e30-1b47-54ec-b978-2c84c6420b12@wars-nicht.de>
	<95738e12-6ed6-daf5-9dcf-6336072e6b15@postgrespro.ru>
	<81ed5480-9bca-361b-9aa0-cbafc2ec2f63@wars-nicht.de>
	<7fde7a91-0ad3-33ac-c348-cf58e4638464@2ndquadrant.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>

Peter Eisentraut <peter.eisentraut@2ndquadrant.com> writes:
> I think using ValidateDate() was the right idea.  That is what we use
> for checking date validity everywhere else.

Note that we've got two different CF entries, and threads, covering
fundamentally the same territory here, ie making to_timestamp et al
behave more sanely.  The other thread is
https://commitfest.postgresql.org/10/713/
https://www.postgresql.org/message-id/flat/1873520224.1784572.1465833145330.JavaMail.yahoo%40mail.ya...

Robert pointed out several times in the other thread that to_timestamp
and friends were intended to be Oracle-compatible, which I agree with.
It was also pointed out that Oracle does range validity checks on the
timestamp component fields, which I verified just now using
http://rextester.com/l/oracle_online_compiler
(which is what I found by googling after discovering that sqlfiddle
isn't working very well, sigh).  I got these results:

select banner as "oracle version" from v$version
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
PL/SQL Release 11.2.0.2.0 - Production
CORE	11.2.0.2.0	Production
TNS for 64-bit Windows: Version 11.2.0.2.0 - Production
NLSRTL Version 11.2.0.2.0 - Production

SELECT TO_TIMESTAMP('2016-06-13 99:99:99', 'YYYY-MM-DD HH24:MI:SS') FROM dual
ORA-01850: hour must be between 0 and 23

SELECT TO_TIMESTAMP('2016-06-13 19:99:99', 'YYYY-MM-DD HH24:MI:SS') FROM dual
ORA-01851: minutes must be between 0 and 59

SELECT TO_TIMESTAMP('2016-06-13 19:59:99', 'YYYY-MM-DD HH24:MI:SS') FROM dual
ORA-01852: seconds must be between 0 and 59

SELECT TO_TIMESTAMP('2016-06-13 19:59:59', 'YYYY-MM-DD HH24:MI:SS') FROM dual
13.06.2016 19:59:59

SELECT TO_TIMESTAMP('2016-06-13 19:59:59', 'YYYY-MM-DD HH:MI:SS') FROM dual
ORA-01849: hour must be between 1 and 12

SELECT TO_TIMESTAMP('2016-02-30 19:59:59', 'YYYY-MM-DD HH24:MI:SS') FROM dual
ORA-01839: date not valid for month specified

SELECT TO_TIMESTAMP('2016-02-29 19:59:59', 'YYYY-MM-DD HH24:MI:SS') FROM dual
29.02.2016 19:59:59

SELECT TO_TIMESTAMP('2015-02-29 19:59:59', 'YYYY-MM-DD HH24:MI:SS') FROM dual
ORA-01839: date not valid for month specified

I think this is sufficient evidence to show that we ought to change
to_timestamp et al. to apply range checking on the component fields.
And while I've not attempted to characterize exactly what Oracle
does with extra spaces, non-matching punctuation, etc, it's also
clear to me that their behavior is different and probably saner
than ours.

So I vote for fixing these functions to behave more like Oracle, and
forgetting about having a separate family of to_date_valid() functions
or optional parameters or anything of the sort.  I might've been in
favor of that, until I saw how far down the rabbit hole this thread
had gotten.  Let's just call it a bug and fix it.

Having range checking after the field scanning phase also changes the
terms of discussion about what we need to do in the scanning phase, since
it would catch many (of course not all) of the problems that arise from
field boundary issues.  So I think we should get the range changing
committed first and then fool with the scanner.

The 0002 patch that Artur sent for this purpose in
https://www.postgresql.org/message-id/22dbe4e0-b550-ca86-8634-adcda0faa159@postgrespro.ru
seems like the right approach to me, though I've not read it in detail
yet.  I propose to work through that and commit it.

I'm much less sold on his 0001 patch, but I tend to agree that what
we want is to adjust the scanner behavior.  I do not like the
reverse-conversion wrapper that Andreas proposes here; quite aside from
micro-efficiency issues, it seems to me that that just begs the question
of how you know what the input is supposed to mean.

In short, I think we should reject this thread + CF entry altogether
and instead move forward with the approach in the other thread.
It's probably too late in the September CF to close out the other
submission entirely, but we could get the range checking committed
and then RWF the other part for reconsideration later.

			regards, tom lane


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



view thread (37+ messages)

Message-ID: <2284.1475010063@sss.pgh.pa.us>
Permalink:  ../2284.1475010063@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/2284.1475010063@sss.pgh.pa.us

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-hackers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, peter.eisentraut@2ndquadrant.com, robertmhaas@gmail.com, adsmail@wars-nicht.de, a.zakirov@postgrespro.ru, jd@commandprompt.com, laurenz.albe@wien.gv.at, andreas@proxel.se, pavel.stehule@gmail.com, jaime.casanova@2ndquadrant.com, euler@timbira.com.br
  Subject: Re: to_date_valid()
  In-Reply-To: <2284.1475010063@sss.pgh.pa.us>
  References: <57786490.9010201@wars-nicht.de> <dcdebc73-ffdd-13a3-d6cd-73e1944a066b@timbira.com.br> <CAJGNTeO75ZPm3qDk9rze7coGyvCZyWm68iEFY3WOYb5w=7OdBg@mail.gmail.com> <5778EA94.1020706@wars-nicht.de> <af97b147-3542-7a55-b651-e0ecae0c8c00@proxel.se> <CAFj8pRDHaeVdwHtZQPXKCSaeAQ_2_jeXHpPCssiOdFYs7UoUTw@mail.gmail.com> <2bc6bcef-cada-1ac7-f9a2-2f6128ca4c3c@proxel.se> <A737B7A37273E048B164557ADEF4A58B5386992E@ntex2010i.host.magwien.gv.at> <b28373f4-7e37-3bc4-25a5-65aef4006cf0@2ndquadrant.com> <579823DF.3080903@commandprompt.com> <e9617e30-1b47-54ec-b978-2c84c6420b12@wars-nicht.de> <95738e12-6ed6-daf5-9dcf-6336072e6b15@postgrespro.ru> <81ed5480-9bca-361b-9aa0-cbafc2ec2f63@wars-nicht.de> <7fde7a91-0ad3-33ac-c348-cf58e4638464@2ndquadrant.com> <2284.1475010063@sss.pgh.pa.us>

* 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