pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ben Hood <ben@relops.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: Domain based on TIMEZONE WITH TIME ZONE
Date: Fri, 11 May 2018 08:24:41 +0100
Message-ID: <1465CD01-C08A-49BF-BCF3-193E6509A703@relops.com> (raw)
In-Reply-To: <71aafbb9-f3d1-a20b-5ebc-0162e04a952a@aklaver.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>
	<CA+bJJbyNTns-AMVUbztjb+zeNZ-z0gH=6vXykZCmjCJiK1GogA@mail.gmail.com>
	<D03AF820-9FFF-414F-8747-B3589FBB9224@relops.com>
	<71aafbb9-f3d1-a20b-5ebc-0162e04a952a@aklaver.com>


> On 10 May 2018, at 23:43, Adrian Klaver <adrian.klaver@aklaver.com> wrote:
> 
> Trying to tame time and time zones is maybe quixotic, but not weird.

Quixotic is a very good description, I’d happily admit that using the UTC domain in this way is not as pragmatic as I thought it would when I introduced it.

> While I was working on my response to Peter I realized that the below:
> 
> CREATE DOMAIN UTC_TIMESTAMP AS TIMESTAMP WITH TIME ZONE CHECK (EXTRACT(TIMEZONE FROM VALUE) = 0);
> 
> might not work the way you expect if you have your server set to 'UTC’.

“Might not work the way you expect it to” is the underlying theme and the overall motivation for trying to master time zones from disparate sources.

> 
> show timezone;
> TimeZone
> ----------
> UTC
> (1 row)
> 
> CREATE DOMAIN UTC_TIMESTAMP AS TIMESTAMP WITH TIME ZONE CHECK (EXTRACT(TIMEZONE FROM VALUE) = 0);
> 
> create table ts_check(id integer, ts_fld utc_timestamp);
> 
> insert into ts_check values (1, now());
> insert into ts_check values (2, '05/10/18 15:23');
> insert into ts_check values (3, '05/10/18 15:23+07');
> 
> 
> test=> select * from ts_check ;
> id |            ts_fld
> ----+-------------------------------
>  1 | 2018-05-10 22:37:58.745263+00
>  2 | 2018-05-10 15:23:00+00
>  3 | 2018-05-10 08:23:00+00
> 
> In fact I am not sure how it works:):

As Peter and Francisco has previously demonstrated, I believe that inserting a timestamp into the UTC_TIMESTAMP column:

(1) Checks the client time zone is UTC
(2) Converts the timestamp to UTC, whether it was presented as UTC or not.

Going to back to the original intention of enforcing UTC, the end result is correct, but for the wrong reason.

In this example, row 3 contains the UTC value of  '05/10/18 15:23+07’, which is the end result I wanted (pure UTC everywhere).

But, the way that it is actually happens under the covers is masked by the use of the UTC_TIMESTAMP domain.

In the scenario, there is a belief that only UTC timestamps are being inserted, which is not true.

The way that Postgres stores any timestamp leads to the desired result, fooling me into believing that the UTC_TIMESTAMP domain is casual for the correct result.

I would have need check whether the behavior is the same using a network client driver (maybe there is some implicit coercion going on when psql parses the statement).

But I think the point still stands that Postgres timestamp handling is doing the real work and is casual for the desired outcome, not the domain.

view thread (36+ messages)  latest in thread

Message-ID: <1465CD01-C08A-49BF-BCF3-193E6509A703@relops.com>
Permalink:  ../1465CD01-C08A-49BF-BCF3-193E6509A703@relops.com/
Also on:    postgresql.org/message-id/1465CD01-C08A-49BF-BCF3-193E6509A703@relops.com

 · 

reply

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: <1465CD01-C08A-49BF-BCF3-193E6509A703@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> <CA+bJJbyNTns-AMVUbztjb+zeNZ-z0gH=6vXykZCmjCJiK1GogA@mail.gmail.com> <D03AF820-9FFF-414F-8747-B3589FBB9224@relops.com> <71aafbb9-f3d1-a20b-5ebc-0162e04a952a@aklaver.com> <1465CD01-C08A-49BF-BCF3-193E6509A703@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