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 1fUub2-0005Ub-01 for pgsql-general@arkaria.postgresql.org; Mon, 18 Jun 2018 13:53:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fUub0-0004r5-D3 for pgsql-general@arkaria.postgresql.org; Mon, 18 Jun 2018 13:53:26 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fUuay-0004qv-Gy for pgsql-general@lists.postgresql.org; Mon, 18 Jun 2018 13:53:26 +0000 Received: from out2-smtp.messagingengine.com ([66.111.4.26]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fUuas-0007Xc-M1 for pgsql-general@postgresql.org; Mon, 18 Jun 2018 13:53:24 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 573D521F59; Mon, 18 Jun 2018 09:53:16 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Mon, 18 Jun 2018 09:53:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc: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=fm3; bh=eA6HU8vrt4a5kf4ZTlDnecLzDALwP ajBYsqHemIY864=; b=nxE+R2jV84E5eTsgoMannl1XOES7FleP2WvRCLnNuqIB+ THPS+pJB9yJG4S0rSTvln8N0/kAIMilOWTlkg7I8bU50lGu824yD+DtwfE0CWlu5 MbeWthWTIWWjb7P3gAvHjvKeh/V9Vda1a6Sg2uLlXtRHx8erTAmDu6sQwFwCSlET ihgeNFqiP2QEnhES3cJSj1KubZJdC1mAYEkQxzCtQJYpmwQl42f35cJXRLcmHJHN oIlvWIb8lWnUX4l3VP4jzHpSDWOyfk1J7jnyCprBfU28c0HrrIDdKmqacuLGm1NM nWQlpQiR5sGhMsluggqm7KXz26PyLn/9LVErcqaKA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=fm3; bh=eA6HU8 vrt4a5kf4ZTlDnecLzDALwPajBYsqHemIY864=; b=jU2yoTcO5/s1zzSXNqHRml PkbHo8mJuwmAGb2U0glJZ/+0K7SdheFrgmkTDA5F6PQc5Z1YOQxRypbDN8WM0x5+ +hf9ozHdIA0Lke6+aeSzIwfHzE3qnOTvEIJNTG0RD49o0SZ/FPBFfdbrLnbxAySH kGHs/Beqg+fUCaAT6DqKBZQB+6VWIKZRnm9EokCxyrDdCJfHCTUNufZ5Yzr3J8Z1 MVV0XreCkjVdg3rrJ0J5OFhc89nBFP/exk7n1E9liP6psKa3Kxl4dZEG7vm8QSD2 iXUmlkzlBPZhvz0v4aRi2RVV1Pt9SGq+hYSKQyDFDSNjiSpKOWaeif1wq8+mAefQ == X-ME-Proxy: X-ME-Sender: Received: from [192.168.1.3] (unknown [71.212.159.209]) by mail.messagingengine.com (Postfix) with ESMTPA id 9B0491037C; Mon, 18 Jun 2018 09:53:15 -0400 (EDT) Subject: Re: Clarifying "timestamp with time zone" To: Jeremy Finzel Cc: Postgres General References: <5c7b75ed-f0bd-7b41-8f97-24e34cf489e2@aklaver.com> From: Adrian Klaver Message-ID: Date: Mon, 18 Jun 2018 06:53:14 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: 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 06/18/2018 06:24 AM, Jeremy Finzel wrote: > > > On Fri, Jun 15, 2018 at 2:57 PM, Adrian Klaver > > wrote: > > On 06/15/2018 12:24 PM, Jeremy Finzel wrote: > > Hello! > > We often prefer to use timestamptz or "timestamp with time zone" > in our environment because of its actually storing "objective > time" with respect to UTC.  But in my own work experience, I > have scarcely encountered a case where business users, and > software engineers, do not actually think it means the opposite. > > When I say "timestamp with time zone", people think the data is > saved *in* a specific time zone, whereas in reality, the > opposite is true.  It is really more like "timestamp UTC" or you > even could say "timestamp at UTC".  When you query this of > course, then it shows you the time offset based on your client > timezone setting. > > I do believe this is part of the SQL standard, but I have found > that it creates great confusion.  I think many devs choose > timestamp instead of timestamptz because they don't really > understand that timestamptz gives you UTC time storage built-in. > > That of course means that if you have multiple servers that run > in a different time zone, and you want to replicate that data to > a centralized location, you can easily figure out what objective > time a record changed, for instance, not knowing anything about > what time zone the source system is in. > > So it seems to me that "timestamp with time zone" is a misnomer > in a big > > > It actually is. It is just one timezone though, UTC. > > way, and perhaps it's worth at least clarifying the docs about > this, or > > > https://www.postgresql.org/docs/10/static/datatype-datetime.html#DATATYPE-TIMEZONES > > > "For timestamp with time zone, the internally stored value is always > in UTC (Universal Coordinated Time, traditionally known as Greenwich > Mean Time, GMT). An input value that has an explicit time zone > specified is converted to UTC using the appropriate offset for that > time zone. If no time zone is stated in the input string, then it is > assumed to be in the time zone indicated by the system's TimeZone > parameter, and is converted to UTC using the offset for the timezone > zone." > > How should the above be clarified? > > > Actually, that is a really good description.  But I would say the > problem is it does not have a prominent place on the page, and that many > people reading the docs will make enough assumptions about the data > types before they get down to this part of the page.  What is displayed > as nitty-gritty details down the page should be essential reading for > any user of postgres wanting to know how to decide between timestamp and > timestamptz. > > There are some descriptions that tend to mislead that perhaps could be > clarified.  For example, at the top of the page, timestamptz is > described as "both date and time, with time zone".  Given what we all > seem to acknowledge is a misleading description, I think we ought to > either change this to summarize the above very helpful description, > perhaps "both date and time, in UTC" or some such idea. > > I like the idea of making that note that is now nested deep in the > example section very prominent at the top of the page, perhaps as one of > these special notes, given how critical timestamps are for nearly any > relational database use. > > Thoughts? Time/dates/timestamps are complicated and there are no end of 'if, and and buts'. My suggestion would be a note at the top of the page that says read through this section at least twice and then come back and do that again. Other gotchas in the section that I have seen in posts to this list: "The SQL standard differentiates timestamp without time zone and timestamp with time zone literals by the presence of a “+” or “-” symbol and time zone offset after the time. Hence, according to the standard, TIMESTAMP '2004-10-19 10:23:54' is a timestamp without time zone, while TIMESTAMP '2004-10-19 10:23:54+02' is a timestamp with time zone. PostgreSQL never examines the content of a literal string before determining its type, and therefore will treat both of the above as timestamp without time zone. To ensure that a literal is treated as timestamp with time zone, give it the correct explicit type: TIMESTAMP WITH TIME ZONE '2004-10-19 10:23:54+02' In a literal that has been determined to be timestamp without time zone, PostgreSQL will silently ignore any time zone indication. That is, the resulting value is derived from the date/time fields in the input value, and is not adjusted for time zone." "One should be wary that the POSIX-style time zone feature can lead to silently accepting bogus input, since there is no check on the reasonableness of the zone abbreviations. For example, SET TIMEZONE TO FOOBAR0 will work, leaving the system effectively using a rather peculiar abbreviation for UTC. Another issue to keep in mind is that in POSIX time zone names, positive offsets are used for locations west of Greenwich. Everywhere else, PostgreSQL follows the ISO-8601 convention that positive timezone offsets are east of Greenwich." > > Thanks, > Jeremy > -- Adrian Klaver adrian.klaver@aklaver.com