From: Ben Hood <ben@relops.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: Domain based on TIMEZONE WITH TIME ZONE
Date: Thu, 10 May 2018 21:14:00 +0100
Message-ID: <467CF53D-9E20-4FC9-9BF6-ED31926C44DB@relops.com> (raw)
In-Reply-To: <CAKFQuwZB2Fi1SodPMeW0PSL07HZs0W8evn_WTTMJCUqtM1eVHA@mail.gmail.com>
References: <06EAD729-DC35-4E48-AB25-C42F7FA19C28@relops.com>
<CA+bJJbz0Gwo8mkyzHa_4qjcNcMV0M00yTZ_LjUtaJu=M=+bpyQ@mail.gmail.com>
<188A0270-0A9A-4ADE-A928-9067E99AE7B7@relops.com>
<20180510103608.GB3622@hermes.hilbert.loc>
<BCC1C385-7AAC-42BD-B790-08D7624C9414@relops.com>
<CALd+dcdCxk00TnL0ey_1Yk-egwwqFjF3BJbiA_=8aJwSjWP6Yw@mail.gmail.com>
<D9289E35-E24B-4C3A-8E76-18220DF01719@relops.com>
<CAKFQuwZB2Fi1SodPMeW0PSL07HZs0W8evn_WTTMJCUqtM1eVHA@mail.gmail.com>
> On 10 May 2018, at 17:35, David G. Johnston <david.g.johnston@gmail.com> wrote:
>
> '2018-05-10T15:23:00-07:00'::timestamptz is unambiguous
That is true. Mandating UTC is not the only way to eliminate ambiguity. Apologies for appearing to suggest that this is case.
>
> Allowing client applications to represent time in the user's timezone is a feature.
Fair point.
> If I send 4pm ET to the server to be stored in a timestamptz field, and fail to tell the server that the timezone is ET in the value itself then I must instead set my session timezone to ET or the server is going to store the wrong value. There is nothing you can do in an default server to prevent this. Tom has described how you could possibly make the "fail to tell the server that the timezone is ET" impossible using a custom type. This seems to be what you want though I'd question whether it is worth the cost.
The domain approach is what has been implemented and has been running in production for some time without a problem (that we know of).
The cost of this appears to be quite trivial in Postgres - there are 2 lines of DDL in the OP that describe the implementation and it seems to work.
The reason why I started this thread is because somebody on a JDBC related list told me that I was crazy for trying to do this and that I had most likely misunderstood how Postgres works. So respecting their opinion, I decided to ask the Postgres experts.
It is heartening to hear Tom say that the idea is not completely insane, but questions the business value of mandating UTC, given there are other ways to ensure timezone explicitness across the app(s) and the database.
I’m also somewhat wiser about Postgres works now as well.
> I'm not sure how binary timestamp values being sent to the server in a BIND command plays into this...
The bit I’m ignorant of is that the domain approach appears to work with the timestampz wire representation. Apps seem to bind using the platform timestampz representation and the server barfs if the app forgets to enforce UTC.
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: ben@relops.com
Subject: Re: Domain based on TIMEZONE WITH TIME ZONE
In-Reply-To: <467CF53D-9E20-4FC9-9BF6-ED31926C44DB@relops.com>
References: <06EAD729-DC35-4E48-AB25-C42F7FA19C28@relops.com> <CA+bJJbz0Gwo8mkyzHa_4qjcNcMV0M00yTZ_LjUtaJu=M=+bpyQ@mail.gmail.com> <188A0270-0A9A-4ADE-A928-9067E99AE7B7@relops.com> <20180510103608.GB3622@hermes.hilbert.loc> <BCC1C385-7AAC-42BD-B790-08D7624C9414@relops.com> <CALd+dcdCxk00TnL0ey_1Yk-egwwqFjF3BJbiA_=8aJwSjWP6Yw@mail.gmail.com> <D9289E35-E24B-4C3A-8E76-18220DF01719@relops.com> <CAKFQuwZB2Fi1SodPMeW0PSL07HZs0W8evn_WTTMJCUqtM1eVHA@mail.gmail.com> <467CF53D-9E20-4FC9-9BF6-ED31926C44DB@relops.com>
* 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