Re: Strategies for converting UTC data to local windows for arbitrary resolutions and timezones

From: Lincoln Swaine-Moore <lswainemoore(at)gmail(dot)com>
To: Alban Hertroys <haramrae(at)gmail(dot)com>
Cc: Marian Wendt <marian(dot)wendt(at)yahoo(dot)com>, pgsql-general <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Strategies for converting UTC data to local windows for arbitrary resolutions and timezones
Date: 2023-10-04 19:30:51
Message-ID: CABcidkLCfH7CPjywobHLq4YNVWd=mS2XWeU4O80qm=_Oqx3LsA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> What I do in such cases is to add an extra column with the UTC timestamp
to serve as a linear scale to the local timestamps. That also helps with
ordering buckets in reports and such during DST changes (especially the
ones where an hour repeats).

> For hours and quarter hours I found it to be fairly convenient to base a
view on a join between a date calendar and an (quarter of an) hour per UTC
day table, but materialising that with some indexes may perform better (at
the cost of disk space). I do materialise that currently, but our database
server doesn’t have a lot of memory so I’m often not hitting the cache and
performance suffers a bit (infrastructure is about to change for the better
though).

That's an interesting idea, but I'm not sure I fully understand. Assuming
you're aggregating data: what do you group by? For instance, at an hourly
resolution, if you group by both the UTC timestamp and the local one, you
might end up, say, dividing an hour-long bucket in two for time zones with
half-hour-based offsets, no?

Thanks for the detailed writeup! Definitely helpful to learn more about
what people are using in production to handle this sort of thing.

--
Lincoln Swaine-Moore

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Brent Wood 2023-10-04 19:48:31 Re: Strategies for converting UTC data to local windows for arbitrary resolutions and timezones
Previous Message Lincoln Swaine-Moore 2023-10-04 19:16:05 Re: Strategies for converting UTC data to local windows for arbitrary resolutions and timezones