Re: Week numbers and calculating weekly statistics/diagrams - Mailing list pgsql-general

From Martijn van Oosterhout
Subject Re: Week numbers and calculating weekly statistics/diagrams
Date
Msg-id 20100216124757.GA10778@svana.org
Whole thread Raw
In response to Week numbers and calculating weekly statistics/diagrams  (Alexander Farber <alexander.farber@gmail.com>)
List 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.

Attachment

pgsql-general by date:

Previous
From: Alban Hertroys
Date:
Subject: Re: Having a plpgsql function return multiple rows that indicate its progress in a cursor like fashion
Next
From: Peter Geoghegan
Date:
Subject: Re: Having a plpgsql function return multiple rows that indicate its progress in a cursor like fashion