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 1fGmd7-0004VF-BA for pgsql-general@arkaria.postgresql.org; Thu, 10 May 2018 14:33:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fGmd5-0007DY-SN for pgsql-general@arkaria.postgresql.org; Thu, 10 May 2018 14:33: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 1fGmd5-0007DO-GV for pgsql-general@lists.postgresql.org; Thu, 10 May 2018 14:33:11 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fGmd2-0000z7-T6 for pgsql-general@lists.postgresql.org; Thu, 10 May 2018 14:33:10 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w4AEX5A8015271; Thu, 10 May 2018 10:33:05 -0400 From: Tom Lane To: Ben Hood cc: pgsql-general@lists.postgresql.org Subject: Re: Domain based on TIMEZONE WITH TIME ZONE In-reply-to: <188A0270-0A9A-4ADE-A928-9067E99AE7B7@relops.com> References: <06EAD729-DC35-4E48-AB25-C42F7FA19C28@relops.com> <188A0270-0A9A-4ADE-A928-9067E99AE7B7@relops.com> Comments: In-reply-to Ben Hood message dated "Thu, 10 May 2018 11:19:36 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <15269.1525962785.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 10 May 2018 10:33:05 -0400 Message-ID: <15270.1525962785@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Ben Hood writes: > So the question is not how does the timestamp get stored, rather, is it = an anti-pattern to use Postgres as a linter for apps that forget to use UT= C exclusively? Well, using a domain to enforce additional constraints on a field's value is certainly not an anti-pattern in itself. But you have to realize that the processing consists of first creating a value of the base type and then applying the constraint expressions of the domain to it. This means you cannot check any details that are lost in the input conversion, because you don't have access to the original input string, only the stored value. As others have explained, Postgres' TIMESTAMP WITH TIME ZONE type doesn't preserve the input's timezone specification (if any) but forcibly rotates to UTC and stores just a scalar UTC value. So you can't use a domain to check anything about whether the input had a timezone field and if so what it was. (This behavior is nonstandard --- the SQL spec evidently expects the timezone to be stored explicitly in some fashion --- but I don't foresee us changing it; we've accumulated too much backwards-compatibility baggage now.) If you're sufficiently intent on having checking of that sort, you could invent your own datatype with your own input function, and then make it binary-compatible with timestamptz so that you don't need to provide much else besides the I/O functions. varchar(n) has the same sort of relationship with text, so there's precedent ... regards, tom lane