Re: help with date_part & day of week

Поиск
Список
Период
Сортировка
От Bruce Momjian
Тема Re: help with date_part & day of week
Дата
Msg-id 200512300236.jBU2ahb17497@candle.pha.pa.us
обсуждение исходный текст
Ответ на Re: help with date_part & day of week  (<me@alternize.com>)
Список pgsql-novice
me@alternize.com wrote:
> > You can really do it using CASE:
> >
> > CASE
> > WHEN dow() = 0 THEN 6
> > ELSE dow() - 1
> > END
>
> how good is this solution in regards to performance? i always thought CASE
> and the such should only be used for last resorts. and now there is also a
> date function involved that gets twice in 6/7 of all cases...
>
> regarding these concerns, can you give me your opinion on this solution i
> came up:
>
> SELECT ((date_part('dow', now()) + 6) % 7) AS weekday

I don't think CASE is any significant performance hit, certainly less
than a pl/pgsql function.  Anyway, your solution looks even cleaner.

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

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

Предыдущее
От: Michael Dean
Дата:
Сообщение: ecommerce soolution
Следующее
От: John DeSoi
Дата:
Сообщение: Re: ecommerce soolution