Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1ruK3j-004Wyk-Ao for pgsql-general@arkaria.postgresql.org; Tue, 09 Apr 2024 22:35:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1ruK3i-00BwAP-Iq for pgsql-general@arkaria.postgresql.org; Tue, 09 Apr 2024 22:35:18 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1ruK3h-00BwAA-NI for pgsql-general@lists.postgresql.org; Tue, 09 Apr 2024 22:35:18 +0000 Received: from fout8-smtp.messagingengine.com ([103.168.172.151]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1ruK3e-0025Dd-Go for pgsql-general@lists.postgresql.org; Tue, 09 Apr 2024 22:35:16 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfout.nyi.internal (Postfix) with ESMTP id 6E4BB13800E7; Tue, 9 Apr 2024 18:35:13 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Tue, 09 Apr 2024 18:35:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm1; t=1712702113; x=1712788513; bh=EeWbqxr7goAofQ8AhzMN7/PdZpgs8xsXQm57zRuBqf8=; b= CHEtSkhEOwfeG1PmaemlIn6q8MgYn5at2pPzdiWY182mHzpWwZW4l/y04WCi6gMw RtWecDjCOeZmtzp2mcu9iGCy2td1XsRFFro8wnKPWqo4zpm4HLj/mrJ4eVIr7Fxk Z78Yo5Q4bJy2h5CLnACTCe3WHlZ38hR6yPrhgaVJDmnoXyrN+d1hLihYOE1phRzn UFJixbReWnmys0TkDqP5cRF1tbrDUXBxHXZUSdsQ4pzRkZvzwPL97++uqaGV2JqF oz/0He1hxT1JWFdAq0oOa5i6JT4urzm/vlCz5UdC/0qKUymZb+CG18KJ7Uad6HHO pSukO8SbL3a6jOHY4MQHqA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1712702113; x= 1712788513; bh=EeWbqxr7goAofQ8AhzMN7/PdZpgs8xsXQm57zRuBqf8=; b=A 3uyg3mw2pqevFoxxrfLRZYOiNm0J13GIZBAB4PFittpiE+Nxz+AvrZ/zhbwAGUxy GOGbynVgrhgK55KQis423BbZ45IH7p1ns+76qDJ/d6XIraTVQqz6RDvbm+1+mphr PSfh6JgOcdC1H+CC25J7rOWiPleLR7VX8Po2BEYc/WMFcSLsiUtN4rFtbjW7YVh5 KJEfe9yFGo1bddVzf+ck+TiIKgR5SFSSO0mCL3WBo+S9N+uysM04ejmxXMa/qvPg HJcKCNlGC9/GQnO78ykJWYD8sr061RUu2zFO4tqCaGUmhbN3JUJtWsSTUwMXcHY3 1tqyU6H1jRzffa9bMAZbQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudehhedguddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefkffggfgfuvfevfhfhjggtgfesth ekredttddvjeenucfhrhhomheptegurhhirghnucfmlhgrvhgvrhcuoegrughrihgrnhdr khhlrghvvghrsegrkhhlrghvvghrrdgtohhmqeenucggtffrrghtthgvrhhnpefgudefke fhveefleevieeuveehvdduudekuddvvdelhfeuueeijedtuedvvedvueenucffohhmrghi nhepphhoshhtghhrvghsqhhlrdhorhhgnecuvehluhhsthgvrhfuihiivgeptdenucfrrg hrrghmpehmrghilhhfrhhomheprggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdr tghomh X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 9 Apr 2024 18:35:12 -0400 (EDT) Message-ID: Date: Tue, 9 Apr 2024 15:35:11 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Issue with date/timezone conversion function To: Lok P , Tom Lane Cc: pgsql-general References: <3756920.1712682208@sss.pgh.pa.us> Content-Language: en-US From: Adrian Klaver In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 4/9/24 11:24, Lok P wrote: > > On Tue, Apr 9, 2024 at 10:33 PM Tom Lane > wrote: > > 'EST' is going to rotate to UTC-5, but that's probably not what > you want in the summer.  I'd suggest AT TIME ZONE 'America/New_York' > or the like.  See > > https://www.postgresql.org/docs/current/datatype-datetime.html#DATATYPE-TIMEZONES > >                         regards, tom lane > > > >  Thank you so much. You are correct. The AT TIME ZONE > 'America/New_York' is giving correct EST time conversion. > > But I think regarding why it looks to be shifting i.e. the same time > duration appears to be holding a different count of transactions while > the base table is not getting updated/inserted/deleted for its > historical create_timestamps, I suspect the below conversion part. > > The task is to count each ~15minutes duration transaction and publish in > ordered fashion i.e. something as below, but the way it's been written > seems wrong. It's an existing script. It first gets the date component > with truncated hour and then adds the time component to it to make it > ~15minutes interval. Can it be written in some simple way? > > 9-apr-2024 14:00     12340 > 9-apr-2024 14:15     12312 > 9-apr-2024 14:30     12323 > 9-apr-2024 14:45     12304 > > /DATE_TRUNC('hour', create_timestamp AT TIME ZONE '/America/New_York'/) +/ > /(EXTRACT(MINUTE FROM create_timestamp AT TIME ZONE > '/America/New_York/') / 15 * 15) * INTERVAL '15 minute'/ Something like?: create table dt_bin_test(id integer, tz_fld timestamptz); insert into dt_bin_test values(1, '2024-04-01 8:15'), (2, '2024-04-01 9:01'), (3, '2024-04-01 9:16'), (4, '2024-04-01 9:45'), (5, '2024-04-01 8:15'), (6, '2024-04-01 9:01'); select count(tz_fld), date_bin('15 minutes', tz_fld, '2024-01-01') as bin from dt_bin_test group by date_bin('15 minutes', tz_fld, '2024-01-01'); count | bin -------+------------------------ 2 | 2024-04-01 09:00:00-07 2 | 2024-04-01 08:15:00-07 1 | 2024-04-01 09:15:00-07 1 | 2024-04-01 09:45:00-07 -- Adrian Klaver adrian.klaver@aklaver.com