pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Peter J. Holzer <hjp-pgsql@hjp.at>
To: pgsql-general@lists.postgresql.org
Subject: Re: Domain based on TIMEZONE WITH TIME ZONE
Date: Thu, 10 May 2018 14:55:19 -0700
Message-ID: <b9d14656-0228-86a7-14d1-1725554bb6ba@aklaver.com> (raw)
In-Reply-To: <20180510211741.icfg5xyqjkdvgmgj@hjp.at>
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>
	<20180510211741.icfg5xyqjkdvgmgj@hjp.at>

On 05/10/2018 02:17 PM, Peter J. Holzer wrote:
> On 2018-05-10 21:37:26 +0100, Ben Hood wrote:
>>      On 10 May 2018, at 16:33, Francisco Olarte <folarte@peoplecall.com> wrote:
>>
>>      For what you want to do I think you'll have to parse the text value,
>>      maybe by definig a view with a text columns and using some
>>      rule/trigger magic for insert / updates.
>>
>>
>> Sorry for being unclear - the solution I have in production appears to work
>> with
>>
>> CREATE DOMAIN UTC_TIMESTAMP AS TIMESTAMP WITH TIME ZONE CHECK (EXTRACT(TIMEZONE
>> FROM VALUE) = 0);
>>
>> This raises an exception when an app doesn’t use UTC.
> 
> I don't understand how this can work. As Francisco demonstrated,
> EXTRACT(TIMEZONE FROM ts) doesn't extract the time zone from the value
> ts, it reports the offset of the client's time zone.
> 
> So, if my time zone is set to Europe/Vienna,
> extract(timezone from '2018-05-10 23:17:44+00'::timestamptz)
> will still return 7200, even though I have explicitely specified a UTC
> timestamp.

It depends on the TimeZone setting in the conf file. So on my machine I 
have two instances of Postgres running. One is set to the timezone set 
by initdb to 'US/Pacific'. In the other I set TimeZone = 'UTC'. Using 
the same client(psql) I get:

'US/Pacific' instance

test=> select now();
               now
-------------------------------
  2018-05-10 14:47:40.903274-07

test=> select extract(timezone from '05/10/18 14:45+00'::timestamptz);
  date_part
-----------
     -25200
(1 row)


----------------------------------------

'UTC' instance
postgres=> select now();
               now
-------------------------------
  2018-05-10 21:47:24.934913+00

postgres=> select extract(timezone from '05/10/18 14:45+00'::timestamptz);
  date_part
-----------
          0
(1 row)
-
> 
> What your check probably does is to enforce that the client's time zone
> is set to UTC.
> 
>          hp
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com




view thread (36+ messages)  latest in thread

Message-ID: <b9d14656-0228-86a7-14d1-1725554bb6ba@aklaver.com>
Permalink:  ../b9d14656-0228-86a7-14d1-1725554bb6ba@aklaver.com/
Also on:    postgresql.org/message-id/b9d14656-0228-86a7-14d1-1725554bb6ba@aklaver.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: adrian.klaver@aklaver.com, hjp-pgsql@hjp.at
  Subject: Re: Domain based on TIMEZONE WITH TIME ZONE
  In-Reply-To: <b9d14656-0228-86a7-14d1-1725554bb6ba@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> <20180510211741.icfg5xyqjkdvgmgj@hjp.at> <b9d14656-0228-86a7-14d1-1725554bb6ba@aklaver.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