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 1fGtXA-0003bn-OL for pgsql-general@arkaria.postgresql.org; Thu, 10 May 2018 21:55:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fGtX8-0000Mp-Tf for pgsql-general@arkaria.postgresql.org; Thu, 10 May 2018 21:55:30 +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 1fGtX7-0000Mg-1L for pgsql-general@lists.postgresql.org; Thu, 10 May 2018 21:55:30 +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 1fGtWz-00038i-Lm for pgsql-general@lists.postgresql.org; Thu, 10 May 2018 21:55:27 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id A94372259F; Thu, 10 May 2018 17:55:20 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Thu, 10 May 2018 17:55:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= content-transfer-encoding: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=X0SrK1ULsh+VuJA7VSoUBZBRsMwrm dFKqU3gzqShwOg=; b=l3h57H7FkCE8jMM89ES3h1uJmdgo+s5ZyJ3EzO/FsWgjn e5P897kMoWxdBzlLFCbTM5V5pOIG1rk1pEJ9NQQPMq8JPVpr5ayaZ/Ix0D13s2nV hgGo6/Y+KToPKUaWwW/fecBMNdI7lX6SfTSAYqVdguBJC9CGzMf5Nhh97sDGolCy ZcwhO2Kihfuy4Fqp7vm7+Bzted4jkZmpoVUznBuU6J0VrfgYKy10xFyQUvTAPO8L 7c6GJthd9QdXzsxAzinJDhLGL/4OCgXJmg1lsdjGPXw6kLhWNl8MuQUELDxJB3tF Cr5KaP9HuZ+UPK7NSWt8uEyTky37WD+iD+aZ7OycQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding: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=X0SrK1 ULsh+VuJA7VSoUBZBRsMwrmdFKqU3gzqShwOg=; b=iq4xiiq7wSkJ2xXg/4xVIx L45UPNP12VWoAhP/b57Jsb55QwUFyISDr4wCdZPDhhIjUmb4BDZ2w0acVnfbEfOf q0ykC2H18yEMSwQyFZh39gGOZwNLkin+oT6s6fGkupQA7/XNpAoe3NaXmPqAcISi 1ZCJXrmN5gLlCBPUgv8SUAdB9pELNKboqeJ7bBfnaukSIpgqYVV18jiRxvoIwJve El+nnBs2XKUiE1Udsqiaup3cUFEfMegHNnPt6mqP2uzF1bZ7pU4ox9R5tbjj3yDC 0L63oxWWbnas6h2u2kqVYYOLgTTxayR1YY0KFVWpUtUiiBnldPzwhuyjhESy0OLA == X-ME-Sender: Received: from [192.168.1.2] (unknown [71.212.135.74]) by mail.messagingengine.com (Postfix) with ESMTPA id 278A510256; Thu, 10 May 2018 17:55:20 -0400 (EDT) Subject: Re: Domain based on TIMEZONE WITH TIME ZONE To: "Peter J. Holzer" , pgsql-general@lists.postgresql.org References: <06EAD729-DC35-4E48-AB25-C42F7FA19C28@relops.com> <188A0270-0A9A-4ADE-A928-9067E99AE7B7@relops.com> <20180510211741.icfg5xyqjkdvgmgj@hjp.at> From: Adrian Klaver Message-ID: Date: Thu, 10 May 2018 14:55:19 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <20180510211741.icfg5xyqjkdvgmgj@hjp.at> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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 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