Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jP8RF-0008T9-3u for pgsql-general@arkaria.postgresql.org; Thu, 16 Apr 2020 17:36:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jP8RD-00044H-Mh for pgsql-general@arkaria.postgresql.org; Thu, 16 Apr 2020 17:36:31 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jP8RC-000403-M6 for pgsql-general@lists.postgresql.org; Thu, 16 Apr 2020 17:36:31 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jP8R8-0000Eb-GE for pgsql-general@lists.postgresql.org; Thu, 16 Apr 2020 17:36:30 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 679C95C0238; Thu, 16 Apr 2020 13:36:24 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Thu, 16 Apr 2020 13:36:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm2; bh=q baLEwLhrN5Mg7e+XAgVrYyJnrI8/4kcT2f9CTvHK3c=; b=gWek5Ej8Q59tOVaXG poBW/0MEJbwFjbyNNv9cwbThnY9E1cZyu0TYvTxBOZF6fACNWQKZU7F1jSujfkk/ C6JKlsC3YqOtjkK0K3gPvcb5XdBZqhH4vecVoK5haHzX0HE/faKe+252OJI6g95+ utVb75QwFhqDs9IC1mc198Q/zsFrBo2nWilyKuGsOpG4wEnGIUXFlTn6rdZhXwSn PxXRltY/NUY2esaCuqNZ9PPxReflibERj5+p/ZcZ3CerAWQ/T+tmwfPsbk3VixMU IVJR8OpYJ91ai1L0nLMjLQeIkom4+aRNAiTOiA2+20qM5/UVYQ0IOx1QMYUxGZoz injnA== 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-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; bh=qbaLEwLhrN5Mg7e+XAgVrYyJnrI8/4kcT2f9CTvHK 3c=; b=Hxq1gAbyauXv8wPqSo84ZFWqxBJIvkXdPTMfCoHiyLxJkmtW1OGZ94Eny dRBY573/HvcmQzVlK07wcwFX0t9nHSv2bp10pmUfuoZ7uVfu9bTc2Rg+6wpBqCiU bROgEqZCDOvrLDetyjrN6huwJEvWqPXk6MM6fdqSppimVQXNagFuVHkp4MR17KuS 7nutvIs6lrnqHzN4AY741ae7lgCCGa0srHjhz/0oDJd6iXwUzt1fy1E4Q3/4R35y ss8Mux6jLpxw74Vyi8sDSdacx3iqIvHfOFTiYR7B5TDsYlSpcabhf4quGpYGepBN OEwjJUmTkOrE8YW02EmcFuYmzdCfA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduhedrfeehgdduudehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefuvfhfhffkffgfgggjtgfgsehtje ertddtfeejnecuhfhrohhmpeetughrihgrnhcumfhlrghvvghruceorggurhhirghnrdhk lhgrvhgvrhesrghklhgrvhgvrhdrtghomheqnecuffhomhgrihhnpehpohhsthhgrhgvsh hqlhdrohhrghenucfkphepleejrdduudefrddvtdejrddufeeknecuvehluhhsthgvrhfu ihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprggurhhirghnrdhklhgrvhgvrh esrghklhgrvhgvrhdrtghomh X-ME-Proxy: Received: from [192.168.1.10] (97-113-207-138.tukw.qwest.net [97.113.207.138]) by mail.messagingengine.com (Postfix) with ESMTPA id 73915306005E; Thu, 16 Apr 2020 13:36:23 -0400 (EDT) Subject: Re: timestamp and timestamptz To: raf , pgsql-general@lists.postgresql.org References: <4757e6ae98474a2897b2fac202466e5e@dst.dk> <87pnc8ieqa.fsf@gmail.com> <20200415235314.ciyqbyikap37ymyr@raf.org> <20200416071908.atryarqqqanmun7d@raf.org> <20200416082305.ng2op5jybjop6pbt@raf.org> From: Adrian Klaver Message-ID: <11b93ad7-d5c7-e8e8-83e3-36b3da7083e0@aklaver.com> Date: Thu, 16 Apr 2020 10:36:22 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <20200416082305.ng2op5jybjop6pbt@raf.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 4/16/20 1:23 AM, raf wrote: > Steve Baldwin wrote: > >> I'm pretty sure you are mistaken. Postgres doesn't store the 'creating' >> time zone in a timestamptz column. >> >> Try doing this before re-running your test: >> >> set timezone to 'utc'; >> >> What you are seeing in your test is an artifact of that timezone setting. >> >> Steve > > Thanks. You're right. > > create table example (t timestamptz not null); > insert into example (t) values (timestamptz '2020-04-16 17:12:33.71768 Australia/Sydney'); > select * from example; > set timezone to 'utc'; > select * from example; > drop table example; > > Does this: > > CREATE TABLE > INSERT 0 1 > t > ------------------------------ > 2020-04-16 17:12:33.71768+10 > (1 row) > > SET > t > ------------------------------ > 2020-04-16 07:12:33.71768+00 > (1 row) > > DROP TABLE > > So it doesn't store the offset, but I've used postgres > for 12 years without knowing that and it hasn't been > a problem. Yay, postgres! > > It doesn't store the offset but, by using timestamptz, > it knows that the timezone is UTC. That's what matters. Well that is somewhat misleading. The value entered is stored as timestamp with an implicit tz of 'UTC'. The issue that trips people up is the format of the input value. If you enter an input with an offset or correct tz value then you have given Postgres an explicit value to work off for converting it to 'UTC'. For what is correct see here: https://www.postgresql.org/docs/12/datatype-datetime.html#DATATYPE-TIMEZONES If you input a value that does not have the above then Postgres uses the SET TimeZone value to implicitly set the input value's tz(as pointed out by David Johnson upstream). In other words Postgres does not assume an input value is in 'UTC'. For the OP's case that could cause issues if the timestamp in the CSV file does not have a proper offset/tz and the client is using a tz other then 'UTC'(as pointed by others upstream). The bottom line is that when dealing with timestamps explicit is better then implicit. > The fact that it knows the time zone is what makes everything > work. Timestamp without time zone is best avoided I think. > > cheers, > raf > > > > > -- Adrian Klaver adrian.klaver@aklaver.com