[HACKERS] Patch: Avoid precision error in to_timestamp().

Поиск
Список
Период
Сортировка
От Erik Nordström
Тема [HACKERS] Patch: Avoid precision error in to_timestamp().
Дата
Msg-id CAHuQZDS76jTYk3LydPbKpNfw9KbACmD=49dC4BrzHcfPv6yA1A@mail.gmail.com
обсуждение исходный текст
Ответы Re: [HACKERS] Patch: Avoid precision error in to_timestamp().  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
Hello hackers,

I stumbled upon a precision issue with the to_timestamp() function that causes it to return unexpected timestamp values. For instance, the query SELECT to_timestamp(1486480176.236538) returns the timestamp "2017-02-07 16:09:36.236537+01", which is off by one microsecond. Looking at the source code, the issue seems to be that the conversion is unnecessarily done using imprecise floating point calculations. Since the target timestamp has microsecond precision, and is internally represented by a 64-bit integer (on modern platforms), it is better to first convert the given floating point value to a microsecond integer and then doing the epoch conversion, rather than doing the conversion using floating point and finally casting to an integer/timestamp.

I am attaching a patch that fixes the above issue.

Regards,

Erik


Вложения

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: [HACKERS] Idea on how to simplify comparing two sets
Следующее
От: Tom Lane
Дата:
Сообщение: Re: [HACKERS] [PATCH] configure-time knob to set default ssl ciphers