Re: to_date_valid()

Поиск
Список
Период
Сортировка
От Peter Eisentraut
Тема Re: to_date_valid()
Дата
Msg-id 7fde7a91-0ad3-33ac-c348-cf58e4638464@2ndquadrant.com
обсуждение исходный текст
Ответ на Re: to_date_valid()  (Andreas 'ads' Scherbaum <adsmail@wars-nicht.de>)
Ответы Re: to_date_valid()  (Andreas 'ads' Scherbaum <adsmail@wars-nicht.de>)
Re: to_date_valid()  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
On 8/15/16 7:33 AM, Andreas 'ads' Scherbaum wrote:
> 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.

It's debatable what is correct here.

Using to_number, the behavior appears to be that a space in the pattern
ignores one character.  For example:

test=# select to_number('123 456', '999 999');to_number
-----------   123456

test=# select to_number('123 456', '999  999');to_number
-----------    12356

Considering that, the above to_date result is not incorrect.

So just squashing the spaces and converting the value back is not a
correct approach to detecting overflow.

I think using ValidateDate() was the right idea.  That is what we use
for checking date validity everywhere else.

-- 
Peter Eisentraut              http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: ICU integration
Следующее
От: Masahiko Sawada
Дата:
Сообщение: Re: Optimization for lazy_scan_heap