Re: Obtaining the Julian Day from a date

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Obtaining the Julian Day from a date
Дата
Msg-id 10750.1094916827@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: Obtaining the Julian Day from a date  ("Karl O. Pinc" <kop@meme.com>)
Ответы Re: Obtaining the Julian Day from a date
Список pgsql-general
"Karl O. Pinc" <kop@meme.com> writes:
> On 2004.09.10 20:32 Bruno Wolff III wrote:
>> If you keep your data in a date field you can get the Julian day
>> by subtracting the appropiate date. You can then do mod on this
>> difference.

> I've been doing:
> CAST (to_char(date, 'J') AS INT)
> but your way seems faster.  Is it?

Date subtraction is extremely fast (it's really the same as integer
subtraction), so yes I'd expect it to beat the pants off doing to_char
and then conversion back to integer.

Another advantage is that you can equally easily adopt *any* base date,
it doesn't have to be Julian day 0.  This would let you shift between
say Monday and Sunday as start-of-the-week without extra logic.

            regards, tom lane

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: What is the postgres version of mysql's "ON DUPLICATE KEY"
Следующее
От: Josué Maldonado
Дата:
Сообщение: pass an array as parameter to a function