Re: date_trunc() in a specific time zone

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: vik.fearing@2ndquadrant.com
Cc: Paul A Jungwirth <pj@illuminatedcomputing.com>, Steve Crawford <scrawford@pinpointresearch.com>, andreas@proxel.se, pgsql-hackers@lists.postgresql.org
Date: 2018-11-13T23:20:30Z
Lists: pgsql-hackers

Attachments

I wrote:
> BTW, I'd been hoping that we could avoid rotate-to-local-and-back
> in Vik's desired case, but after further thought I suspect the only
> real optimization that's possible compared to writing it out with
> two AT TIME ZONE constructs is to do the zone name lookup just once.
> As an example, truncating to a day-or-larger boundary could result in
> shifting to a different UTC offset than you started with, due to crossing
> a DST boundary.

Here's a v2 that transposes the code to C so that we can get that
optimization.  I've not tried to time it, but it should actually be
a bit faster than standard date_trunc plus one AT TIME ZONE rotation,
never mind two of them.

			regards, tom lane

Commits

  1. Add a timezone-specific variant of date_trunc().