From: Tom Lane <tgl@sss.pgh.pa.us>
To: Lincoln Swaine-Moore <lswainemoore@gmail.com>
Cc: Marian Wendt <marian.wendt@yahoo.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Strategies for converting UTC data to local windows for arbitrary resolutions and timezones
Date: Wed, 04 Oct 2023 12:54:18 -0400
Message-ID: <2602231.1696438458@sss.pgh.pa.us> (raw)
In-Reply-To: <CABcidkLmpJ6GrW9ma6mQq1vVEjdoLxtxndfr9E-zJNCKa9bPVw@mail.gmail.com>
References: <CABcidkJzoCFTX1Bkn8aCSPgH-3BwR8MO8=uHY2r48s1ynNbbJQ@mail.gmail.com>
<CAEfWYywLggL0UJbnQxsafqmkkHYzrU494iEDgHxC=JMdCUj5rQ@mail.gmail.com>
<2582288.1696428710@sss.pgh.pa.us>
<13eb1e62-9c00-4878-bb82-ef003eca884c@yahoo.com>
<CABcidkLmpJ6GrW9ma6mQq1vVEjdoLxtxndfr9E-zJNCKa9bPVw@mail.gmail.com>
Lincoln Swaine-Moore <lswainemoore@gmail.com> writes:
>>> create function generate_series(timestamptz, timestamptz, interval, text)
>>> returns setof timestamptz
>>> strict immutable language plpgsql as
>>> $$
>>> begin
>>> perform set_config('timezone', $4, true);
>>> return query select generate_series($1, $2, $3);
>>> end
>>> $$ set timezone = 'UTC';
> This is a nice suggestion, and in fact, it would be fine from my
> perspective to reset to UTC every time. My concern is only around the
> safety of the final `set timezone`. Under what circumstances/when can I
> count on that being set? E.g. if a query using that function was cancelled
> before finishing, would the connection timezone remain as $4?
No. The function call mechanism will ensure that timezone goes back
to its previous state at function exit. (In the case of an error
exit, that's actually handled by the transaction abort logic, but the
result is the same.) Because of that, I think it doesn't really
matter whether the set_config call says "true" or "false", but saying
that it's a local setting seems less confusing.
> Does that mean I could run this
> outside this context of a function, and expect the setting to go back to
> UTC on a rollback?
An actual rollback would undo the effects of set_config, yes. You
only need this function wrapper to ensure that subsequent operations
in the same transaction don't see the setting change.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: tgl@sss.pgh.pa.us, lswainemoore@gmail.com, marian.wendt@yahoo.com
Subject: Re: Strategies for converting UTC data to local windows for arbitrary resolutions and timezones
In-Reply-To: <2602231.1696438458@sss.pgh.pa.us>
References: <CABcidkJzoCFTX1Bkn8aCSPgH-3BwR8MO8=uHY2r48s1ynNbbJQ@mail.gmail.com> <CAEfWYywLggL0UJbnQxsafqmkkHYzrU494iEDgHxC=JMdCUj5rQ@mail.gmail.com> <2582288.1696428710@sss.pgh.pa.us> <13eb1e62-9c00-4878-bb82-ef003eca884c@yahoo.com> <CABcidkLmpJ6GrW9ma6mQq1vVEjdoLxtxndfr9E-zJNCKa9bPVw@mail.gmail.com> <2602231.1696438458@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox