Re: generate_series for timestamptz and time zone problem

From: Przemysław Sztoch <przemyslaw(at)sztoch(dot)pl>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: generate_series for timestamptz and time zone problem
Date: 2022-06-01 14:45:16
Message-ID: c7ca451a-0145-503a-ce43-fe9f4737f17e@sztoch.pl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Tom Lane wrote on 31.05.2022 22:54:
> =?UTF-8?Q?Przemys=c5=82aw_Sztoch?= <przemyslaw(at)sztoch(dot)pl> writes:
>> |generate_series| ( /|start|/ |timestamp with time zone|, /|stop|/
>> |timestamp with time zone|, /|step|/ |interval| )
>> produces results depending on the timezone value set:
> That's intentional. If you don't want it, maybe you should be using
> generate_series on timestamp without time zone?
>
> regards, tom lane
1. Of course it is intentional.  And usually everything works as it should.

But with multi-zone applications, using timestamptz generates a lot of
trouble.
It would be appropriate to supplement a few functions with the
possibility of specifying a zone (of course, for timestamptz variants):
- generate_series
- date_bin (additionally  with support for months and years)
- timestamptz_plus_interval (the key issue is adding months and years,
"+" operator only does this in the local zone)

Not everything can be solved by converting the time between timestamptz
and timestamp (e.g. using the timezone function).
Daylight saving time reveals additional problems that are not visible at
first glance.

Just if DST did not exist, a simple conversion (AT TIME ZONE '...')
would have been enough.
Unfortunately, DST is popular and, additionally, countries modify their
time zones from time to time.

2. Because I lack the necessary experience, I want to introduce changes
in parts.
There is patch for first function timestamptz_plus_interval.

I don't know how to properly correct pg_proc.dat and add a variant of
this function with 3 arguments now.

Please comment on the patch and provide tips for pg_proc.
If it works for me, I will improve generate_series.

--
Przemysław Sztoch | Mobile +48 509 99 00 66

Attachment Content-Type Size
timestamptz_plus_interval_with_timezone.patch text/plain 5.4 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2022-06-01 14:55:28 Re: pg_upgrade test writes to source directory
Previous Message Tom Lane 2022-06-01 14:41:38 Re: funcs.sgml - wrong example