Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iCqjx-000073-2R for pgsql-general@arkaria.postgresql.org; Tue, 24 Sep 2019 19:44:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iCqjv-0005sz-VG for pgsql-general@arkaria.postgresql.org; Tue, 24 Sep 2019 19:44:47 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1iCqju-0005sm-DZ for pgsql-general@lists.postgresql.org; Tue, 24 Sep 2019 19:44:47 +0000 Received: from wout1-smtp.messagingengine.com ([64.147.123.24]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iCqjm-0002yO-3n for pgsql-general@lists.postgresql.org; Tue, 24 Sep 2019 19:44:46 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 77D44462; Tue, 24 Sep 2019 15:44:34 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Tue, 24 Sep 2019 15:44:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:cc:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm1; bh=a 9xp5PGo1K0QSEzuxJw7+PlnWO2/SKAY/wB8yPD7woA=; b=KR9nN1K8Wg22sfZhh DRBGSnvs3JQeThQC1m0hVPuPf+pGm2LbPmz5zcLOW4272P+eEcH9VD2G6LeJdth1 1qG3dAj9ZkBKovYjwjdi3CxJ2tFcYrPEv2sRVJfc9uEEnbKyb5mTxxE1SVRMkjIS 7ePMYuMzkzMsDq2Q4apuwCxn7aQAcz/tSHqqr20b9MjJ4LG+YW3oIsmRRJcd/BKY wtK7g4CRQcYp1C0hSv2EmUQqhEht0pt8rv+dUc9O7sSbbNp+09aJRNlHAmUn3+In bWXJ4CxLbtTQ06VHIAx/D4bm6vrgbLGqHBFHy5xU7FCL2LfTzQB/KjIxR8A8o46T cfjjg== 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-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; bh=a9xp5PGo1K0QSEzuxJw7+PlnWO2/SKAY/wB8yPD7w oA=; b=ykvm2PG5TrQ489m08M400r9mYHgm3H3Zc2PWR095q9oYYHGiEsuorm7Y8 vFzw9c9yDWpFuH7XwYZKiNwXsp1qddGRdngzoQUty8oVkU9qXZYJCdodkzmJNUbK w8acSymdWRB8qCyTSdaCRVObqDQJi4NkuJ19R5vp6AUOoFvdANhAqZKckGXDLcwn AVGOyNOAVqE/ePvVJH1UQEq1J8rEhUnM6I3dCo04lcdLcHqTNruBscVmkpCz9sHK rSEP/446bbX6gP72+Y6jy8eckvRbWNOXuJM6nE8pXSQf75/bLvsHjvujRuvdzpmO 1QeoDG9thCMJNtwSvT2qmxGvDBYfQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrfedtgddugedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepuffvfhfhkffffgggjggtgfesthejredttdefjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucfkphepudejgedrvddurdejkedrudeikeenucfrrghrrghmpehmrghilhhfrhho mheprggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomhenucevlhhushhtvg hrufhiiigvpedt X-ME-Proxy: Received: from [192.168.1.3] (174-21-78-168.tukw.qwest.net [174.21.78.168]) by mail.messagingengine.com (Postfix) with ESMTPA id 25A0880062; Tue, 24 Sep 2019 15:44:33 -0400 (EDT) Subject: Re: How to get timezone offset in timestamp with time zone AT TIME ZONE output. To: Andrew Gierth Cc: Paul McGarry , pgsql-general@lists.postgresql.org References: <87impio1tf.fsf@news-spur.riddles.org.uk> From: Adrian Klaver Message-ID: <91469459-36f7-41a4-09e9-c88d693cccef@aklaver.com> Date: Tue, 24 Sep 2019 12:44:32 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: <87impio1tf.fsf@news-spur.riddles.org.uk> 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 9/23/19 7:40 PM, Andrew Gierth wrote: >>>>>> "Adrian" == Adrian Klaver writes: > > Adrian> This has come up before and the general suggestion has been to > Adrian> have a column for a naive(timestamp w/o tz) timestamp and a > Adrian> column for the timezone. > > No, that's usually (not always) backwards, and in any event wouldn't > solve this particular issue. > The issue is unclear so I am not sure you can discount this as a solution. The OP had: CREATE TABLE users ( user_id biginit, user_timezone text, -- Eg 'Australia/Sydney','Asia/Hong_Kong' ); CREATE TABLE data ( id bigint, user_id bigint, datetime timestamp with time zone, ); INSERT INTO users (1,'Australia/Sydney'); INSERT INTO users (2,'Asia/Hong_Kong'); INSERT INTO data (5,1,'2020-04-05 02:00:00'); INSERT INTO data (6,2,'2020-04-05 02:00:00'); and: "Therefore whatever renders the offset needs to be capable of doing it per row, independently of the server/session time zone." There is no indication of what the server timezone is set to or where the timestamps being assigned to date.datetime are coming from. Do they originate as local time(per user) or are they being generated server side? -- Adrian Klaver adrian.klaver@aklaver.com