Re: Week numbers and calculating weekly statistics/diagrams

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Alexander Farber <alexander(dot)farber(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Week numbers and calculating weekly statistics/diagrams
Date: 2010-02-16 12:47:58
Message-ID: 20100216124757.GA10778@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)svana(dot)org> http://svana.org/kleptog/
> Please line up in a tree and maintain the heap invariant while
> boarding. Thank you for flying nlogn airlines.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Peter Geoghegan 2010-02-16 13:09:20 Re: Having a plpgsql function return multiple rows that indicate its progress in a cursor like fashion
Previous Message Alban Hertroys 2010-02-16 12:41:01 Re: Having a plpgsql function return multiple rows that indicate its progress in a cursor like fashion