Re: Date calculation

Поиск
Список
Период
Сортировка
От Andrew Gierth
Тема Re: Date calculation
Дата
Msg-id 875zu4a6ox.fsf@news-spur.riddles.org.uk
обсуждение исходный текст
Ответ на Re: Date calculation  (Bruce Momjian <bruce@momjian.us>)
Список pgsql-general
>>>>> "Bruce" == Bruce Momjian <bruce@momjian.us> writes:

 Bruce> Oh, right, you want date, so use:

 Bruce>    SELECT date_trunc('week', CURRENT_DATE) + '6 days';

Three major things wrong with this:

1. If you do this on Sunday, it gives you the current day not the _next_
Sunday.

2. If you try and do this for other days of the week it doesn't work at
all, instead giving you the specified day of the current week whether or
not it's before or after the current day.

3. It's letting PG cast the date to a timestamptz, which is inefficient,
possibly incorrect, and mutable; you want to force it to cast to
timestamp without timezone instead. (A good rule of thumb is that you
virtually never want to cast dates to timestamptz; the natural cast from
date is to timestamp _without_ timezone.)

-- 
Andrew (irc:RhodiumToad)


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

Предыдущее
От: Andrew Gierth
Дата:
Сообщение: Re: Date calculation
Следующее
От: Brad Leupen
Дата:
Сообщение: FK Constraint with ON DELETE SET DEFAULT cascading as table owner