Re: date comparisons

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: date comparisons
Дата
Msg-id 5052.1165944322@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: date comparisons  ("Belinda M. Giardine" <giardine@bio.cse.psu.edu>)
Ответы Re: date comparisons  ("Belinda M. Giardine" <giardine@bio.cse.psu.edu>)
Re: date comparisons  (Richard Huxton <dev@archonet.com>)
Re: date comparisons  (Bruce Momjian <bruce@momjian.us>)
Список pgsql-general
"Belinda M. Giardine" <giardine@bio.cse.psu.edu> writes:
> Should it be this way?

Well, to_timestamp() is apparently designed not to complain when the
input doesn't match the format, which is not my idea of good behavior
... but your example is in fact wrong.  'Month' means a 9-character
field, so you are short a couple of spaces.

regression=# select to_timestamp('January 2006', 'Month YYYY');
      to_timestamp
------------------------
 0006-01-01 00:00:00-05
(1 row)

regression=# select to_timestamp('January   2006', 'Month YYYY');
      to_timestamp
------------------------
 2006-01-01 00:00:00-05
(1 row)

You probably want

regression=# select to_timestamp('January 2006', 'FMMonth YYYY');
      to_timestamp
------------------------
 2006-01-01 00:00:00-05
(1 row)

Or, as suggested upthread, forget to_timestamp and just use the native
timestamp or date input conversion, which on the whole is a lot more
robust (it *will* throw an error if it can't make sense of the input,
unlike to_timestamp).

            regards, tom lane

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

Предыдущее
От: Bruce Momjian
Дата:
Сообщение: Re: Restore database from files (not dump files)?
Следующее
От: Paul Silveira
Дата:
Сообщение: Re: shell script to populate array values