Re: to_date_valid()

From: Artur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>
To: Andreas 'ads' Scherbaum <adsmail(at)wars-nicht(dot)de>, "Joshua D(dot) Drake" <jd(at)commandprompt(dot)com>, Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, Albe Laurenz <laurenz(dot)albe(at)wien(dot)gv(dot)at>, 'Andreas Karlsson *EXTERN*' <andreas(at)proxel(dot)se>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Jaime Casanova <jaime(dot)casanova(at)2ndquadrant(dot)com>, Euler Taveira <euler(at)timbira(dot)com(dot)br>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: to_date_valid()
Date: 2016-08-15 11:44:19
Message-ID: 198c569d-4bd0-7ddb-05c7-113845aec37b@postgrespro.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 15.08.2016 14:33, Andreas 'ads' Scherbaum wrote:
>> Is it right and "true" way to validate date by extra transforming and
>> comparison?
>>
>> Maybe validate date by using ValidateDate(). Attached sample patch.
>
> This does not solve the problem at hand, and let's wrong dates/formats
> slip through:
>
> ./buildclient.py -v -c demo-config-pg.yaml --run-configure --run-make
> --run-install --no-clean-at-all --patch
> 'https://www.postgresql.org/message-id/95738e12-6ed6-daf5-9dcf-6336072e6b15%40postgrespro.ru'
>
>
>
> postgres=# SELECT to_date('2011 12 18', 'YYYY MM DD');
> to_date
> ------------
> 2011-12-08
> (1 row)
>
>
> That is from the regression tests, and obviously handles the date
> transformation wrong. My attempt catches this, because I compare the
> date with the input date, and do not rely on a valid date only.

I suppose that your sample query is an another issue, not date validate
task. I sent the patch to the thread
https://www.postgresql.org/message-id/b2a39359-3282-b402-f4a3-057aae500ee7@postgrespro.ru
. It fixes formatting issues.

I thought that it is better to distinguish this issues to:
- validation of input date/timestmap string and input format string
- result date/timestamp validation

--
Artur Zakirov
Postgres Professional: http://www.postgrespro.com
Russian Postgres Company

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2016-08-15 11:54:07 Re: [Patch] Temporary tables that do not bloat pg_catalog (a.k.a fast temp tables)
Previous Message Andreas 'ads' Scherbaum 2016-08-15 11:33:43 Re: to_date_valid()