Re: Week numbers and calculating weekly statistics/diagrams

Поиск
Список
Период
Сортировка
От Martijn van Oosterhout
Тема Re: Week numbers and calculating weekly statistics/diagrams
Дата
Msg-id 20100216124757.GA10778@svana.org
обсуждение исходный текст
Ответ на Week numbers and calculating weekly statistics/diagrams  (Alexander Farber <alexander.farber@gmail.com>)
Список pgsql-general
On Tue, Feb 16, 2010 at 01:14:26PM +0100, Alexander Farber wrote:
> Does anybody has an advice how to save the week number?
>
> If I save it as a timestamp then calculating realtime statistics
> (on a player profile click) will probably be CPU-intensive,
> because I have to calculate the week numbers each time.

You should probably seperate the storage from the representation. The
easiest way of storing the information of a week is the date of the
first day (after all, a week could begin on a sunday or monday,
depending on your point of view). This will make grouping and searching
quick, as it's just an integer.

If you really wanted to you could choose an epoch and count weeks from
there but I doubt that's worth the effort.

As for how you represent it to the users, you'll have to create some
conversion routine for output, but I seriously doubt that's going to be
a bottleneck.

Have a nice day,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Please line up in a tree and maintain the heap invariant while
> boarding. Thank you for flying nlogn airlines.

Вложения

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

Предыдущее
От: Alban Hertroys
Дата:
Сообщение: Re: Having a plpgsql function return multiple rows that indicate its progress in a cursor like fashion
Следующее
От: Peter Geoghegan
Дата:
Сообщение: Re: Having a plpgsql function return multiple rows that indicate its progress in a cursor like fashion