Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fGrx6-0004tN-3X for pgsql-general@arkaria.postgresql.org; Thu, 10 May 2018 20:14:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fGrx5-0006VG-1y for pgsql-general@arkaria.postgresql.org; Thu, 10 May 2018 20:14:11 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fGrx4-0006V6-Le for pgsql-general@lists.postgresql.org; Thu, 10 May 2018 20:14:10 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fGrx0-0000l9-SA for pgsql-general@lists.postgresql.org; Thu, 10 May 2018 20:14:09 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id C5AFF224CE; Thu, 10 May 2018 16:14:05 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 10 May 2018 16:14:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=relops.com; h= content-type:date:from:in-reply-to:message-id:mime-version :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc; s= mesmtp; bh=sljoiY5Z869M9RwzPg8VzLzb9y/rWXVrDPUk4qcpcyM=; b=1eOII 00wpnffKLrMM5bgfSOz83L/mC+0QzW/3WtMTUfxjNw6BYQdqdyJj5xzzs73fOZDG i9ikCQHGQIms9zntTp/uzdVspoATeEjB4s1UuhwAVXu6t0fIpYKFE6nR979q2Muc AVyOYMeCAwLbmPfkErC1wEfSStqOdWT1A8Zyxk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; bh=sljoiY5Z869M9RwzPg8VzLzb9y/rW XVrDPUk4qcpcyM=; b=P59FBXBeNKVoMO8ujhIYe8bhrnJJzJcxkb4T+ZSOkqIMn 6Oz5Y8CD18R+ljJRbVTOoXj1BJFrveQsEi5gxeRaqvZVmae6+mBDNURQcrVCilHh 1fdSaJS6m2Cco4e6xAdazQ347tzHCvI12K6/ABgs8rdSGT/a5iH3aY3psqtMJbe9 PqDidr6Z/I97umrY0VmsCrhdbdZOCuUbCNkHg7oWObGWs/OxApR9nxd173atE72k 3dyvI38RfpGBKS2VE1ne3BAQfl0Udf1Uax6cKZ2dN6AHfMG4HboYV/rZScGoY1Sn rxUtCpdOm7Hpm1SQyt9VFfDhS610rYZ8UtUp1gLqQ== X-ME-Sender: Received: from [172.20.10.3] (unknown [148.252.128.195]) by mail.messagingengine.com (Postfix) with ESMTPA id 6B794E4393 for ; Thu, 10 May 2018 16:14:04 -0400 (EDT) From: Ben Hood Content-Type: multipart/alternative; boundary="Apple-Mail=_6DBEC031-D847-48A9-856F-9A2CA2126D09" Mime-Version: 1.0 (Mac OS X Mail 11.3 \(3445.6.18\)) Subject: Re: Domain based on TIMEZONE WITH TIME ZONE Date: Thu, 10 May 2018 21:14:00 +0100 References: <06EAD729-DC35-4E48-AB25-C42F7FA19C28@relops.com> <188A0270-0A9A-4ADE-A928-9067E99AE7B7@relops.com> <20180510103608.GB3622@hermes.hilbert.loc> To: pgsql-general@lists.postgresql.org In-Reply-To: Message-Id: <467CF53D-9E20-4FC9-9BF6-ED31926C44DB@relops.com> X-Mailer: Apple Mail (2.3445.6.18) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --Apple-Mail=_6DBEC031-D847-48A9-856F-9A2CA2126D09 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On 10 May 2018, at 17:35, David G. Johnston = wrote: >=20 > =E2=80=8B'2018-05-10T15:23:00-07:00=E2=80=8B'::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. >=20 > 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=E2=80=99m 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=E2=80=99m 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. --Apple-Mail=_6DBEC031-D847-48A9-856F-9A2CA2126D09 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8

On 10 May 2018, at 17:35, David G. Johnston = <david.g.johnston@gmail.com> wrote:

=E2=80=8B'2018-05-10T15:2= 3:00-07:00=E2=80=8B'::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=E2=80=99m 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=E2=80=99= 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.

= --Apple-Mail=_6DBEC031-D847-48A9-856F-9A2CA2126D09--