simplify case statement with function?

Поиск
Список
Период
Сортировка
От Rory Campbell-Lange
Тема simplify case statement with function?
Дата
Msg-id 20020627215844.GA5341@campbell-lange.net
обсуждение исходный текст
Список pgsql-novice
I have a case statement that is quite long to write!

I'd be greteful to know if I can simplify this by using a function, and
if so how I would go about 1) defining it and 2) using it.

Thanks for any help.



select id, idtext, title,
    case when n_msgs > 0 then n_msgs else 0 end as n_ms,
case
when
    ceil((extract(epoch from current_timestamp) - extract(epoch from ts_modified))/ (60 *60)) < 2
then 1
when
    ceil((extract(epoch from current_timestamp) - extract(epoch from ts_modified))/ (60 *60)) < 4
then 4
when
    ceil((extract(epoch from current_timestamp) - extract(epoch from ts_modified))/ (60 *60)) < 8
then 8
when
    ceil((extract(epoch from current_timestamp) - extract(epoch from ts_modified))/ (60 *60)) < 24
then 24
else
    2000
end as hours


--
Rory Campbell-Lange
<rory@campbell-lange.net>
<www.campbell-lange.net>



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

Предыдущее
От: cmasters
Дата:
Сообщение: Re: Help with creating function
Следующее
От: Josh Berkus
Дата:
Сообщение: Re: Date Question