(8.1) to_timestamp correction (epoch to timestamptz)

Поиск
Список
Период
Сортировка
От Michael Glaesemann
Тема (8.1) to_timestamp correction (epoch to timestamptz)
Дата
Msg-id C81EBABC-4C3F-11D9-8726-000A95C88220@myrealbox.com
обсуждение исходный текст
Ответы Re: (8.1) to_timestamp correction (epoch to timestamptz)  (Bruce Momjian <pgman@candle.pha.pa.us>)
Re: (8.1) to_timestamp correction (epoch to timestamptz)  (Bruce Momjian <pgman@candle.pha.pa.us>)
Список pgsql-patches
Note: This patch is intended for 8.1 (as was the original).

I believe the previous patch I submitted to convert Unix epoch to
timestamptz contains a bug relating to its use of AT TIME ZONE. Please
find attached a corrected patch diffed against HEAD, which includes
documentation.

The original function was equivalent to

CREATE FUNCTION to_timestamp (DOUBLE PRECISION)
     RETURNS timestamptz
     LANGUAGE SQL AS '
     select (
         (\'epoch\'::timestamptz + $1 * \'1 second\'::interval)
             at time zone \'UTC\'
         )
     ';

The AT TIME ZONE 'UTC' removes the time zone from the timestamptz,
returning timestamp. However, the function is declared to return
timestamptz. The original patch appeared to work, but creating this
equivalent function fails as it doesn't return the declared datatype.

The corrected function restores the time zone with an additional AT
TIME ZONE 'UTC':

CREATE FUNCTION to_timestamp (double precision)
     returns timestamptz
     language sql as '
     select (
         (\'epoch\'::timestamptz + $1 * \'1 second\'::interval)
             at time zone \'UTC\'
         ) at time zone \'UTC\'
     ';


Michael Glaesemann
grzm myrealbox com



Вложения

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: [HACKERS] 8.0.0beta5 FailedAssertion (Crash) when casting composite types
Следующее
От: Peter Eisentraut
Дата:
Сообщение: Re: [HACKERS] regression script/makefile exit failure