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 1kMgGr-0006Di-R6 for pgsql-general@arkaria.postgresql.org; Sun, 27 Sep 2020 23:39:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kMgGq-0002vx-QI for pgsql-general@arkaria.postgresql.org; Sun, 27 Sep 2020 23:39:56 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kMgGp-0002vq-GD for pgsql-general@lists.postgresql.org; Sun, 27 Sep 2020 23:39:56 +0000 Received: from [66.111.4.28] (helo=out4-smtp.messagingengine.com) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kMgGm-0006DF-Nj for pgsql-general@lists.postgresql.org; Sun, 27 Sep 2020 23:39:54 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id AF2435C0156 for ; Sun, 27 Sep 2020 19:39:41 -0400 (EDT) Received: from imap8 ([10.202.2.58]) by compute3.internal (MEProxy); Sun, 27 Sep 2020 19:39:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anullvalue.net; h=mime-version:message-id:in-reply-to:references:date:from:to :subject:content-type; s=fm1; bh=HuxRSsiFQNZwdyWePNTAjN9zDGUV7VK XNo9ZGB6b3Kc=; b=bnpadEqWgPRnZrFnkoSmCzZBw6mk/d5UFMMHEdbUd0V8tQm TQHfmzxbdfgdkAGqmhqo2gJAb65mdqL8LAQs7cLeGkGzBhxWW/i7huFZDuatNY8B WxKNXenLplX8xETz+JhKlzJ+Ttx4OK3CrdnCsfc0XdTPzKR3z7nHKgPCed/vjMMb B1g0cRY+NCSiaXgSRpXxa6H0aW6IU7g3lHLpnD/IP3OsC4pv6y2VvaFEcS2NU+PQ mhlABfsG4ZlBCR/3bzeaNZfYEdtI8SZ3J0/FrEfiPfXtD6PYBMV0Oc5tIeY3WDr1 HLYSaZpZ0y4zU7IxaN5ZhaCnZD7YH7SxLDA9SWA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=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=HuxRSs iFQNZwdyWePNTAjN9zDGUV7VKXNo9ZGB6b3Kc=; b=ANmzbsGbsYuKjlz3OipVEy fHGm3YJoghIdloUwTEFignKyBhmBJsZeNJ1/O9x7PR3BNDPoVnBG+aclvgenLsAo NLdPhh+/pKOIWKqcLTYlRvUt+4Yh9QGXvZPdhq3EplL7Jmf9JopajrSUeWRuyOoW uApjY8gqhjnyzCgX8OjTEIhY11QmGwLo1eQ/x/U6IoNEYGwYyZGmXH6tS3KeIB1Q rKvE4UskEkxRlMAxanhEpdYjWlUzaENkYyiPGxMVAV5o3RkRooJzX8N49e96W/an 7HffP10slnFV3/iFZSkdYhuy01fTQ68qi+vD4nfneDgteiXw/XkODVLPKcAricqA == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrvdehgddvgecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepofgfggfkjghffffhvffutgesrgdtre erreerjeenucfhrhhomhepfdgrpfhulhhlgggrlhhuvgculdffrhgvficuufhtvghmvghn mddfuceoughrvgifsegrnhhulhhlvhgrlhhuvgdrnhgvtheqnecuggftrfgrthhtvghrnh epveehhfekheevvdefueehteeitdfhtddtudekueelveegtdeutdethfeijeetvdfhnecu vehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepughrvgifse grnhhulhhlvhgrlhhuvgdrnhgvth X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 6E649520094; Sun, 27 Sep 2020 19:39:41 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.3.0-355-g3ece53b-fm-20200922.004-g3ece53b9 Mime-Version: 1.0 Message-Id: <8616533e-6bf1-4f74-880d-d396aede800a@www.fastmail.com> In-Reply-To: <6b269cb9-5572-acaa-de9c-fe1c705fed11@gmail.com> References: <3af9fdd2-b622-426a-8e1e-aeab1bee8493@www.fastmail.com> <6b269cb9-5572-acaa-de9c-fe1c705fed11@gmail.com> Date: Sun, 27 Sep 2020 19:38:43 -0400 From: "aNullValue (Drew Stemen)" To: pgsql-general@lists.postgresql.org Subject: =?UTF-8?Q?Re:_Returning_timestamp_with_timezone_at_specified_timezone_ir?= =?UTF-8?Q?respective_of_client_timezone?= Content-Type: multipart/alternative; boundary=c175ebddb13b4992ad8f61e80f62d958 X-Host-Lookup-Failed: Reverse DNS lookup failed for 66.111.4.28 (deferred) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --c175ebddb13b4992ad8f61e80f62d958 Content-Type: text/plain At 2020-09-27T19:13:09-04:00, Ron sent: > On 9/27/20 4:16 PM, aNullValue (Drew Stemen) wrote: > >> Hello, >> >> I've attempted to obtain help with this problem from several other places, but numerous individuals recommended I ask this mailing list. >> >> What I need is for the ability to return a timestamp with timezone, using the UTC offset that corresponds to a column-defined timezone, irrespective of the client/session configured timezone. >> >> I have three columns in a table: >> Timezone: 'US/Eastern' >> Date: 2020-10-31 >> Time: 08:00 >> >> The output I'm able to find includes these possibilities: >> '2020-10-31 08:00:00' >> '2020-10-31 12:00:00+00' >> >> Whereas what I actually need is: >> '2020-10-31 08:00:00-05' >> >> Using the postgresql session-level timezone configuration won't work because I need multiple timezones to be handled in a single set. >> >> Example code follows. I'm not using to_char in the examples as I likely would in the production code, but I haven't found any way that it could be helpful here regardless. >> > [snip] > >> >> id | timezone | loc_date | loc_time | tswtz | tswotz >> ----+------------+------------+----------+------------------------+--------------------- >> 7 | US/Central | 2020-10-31 | 08:00 | 2020-10-31 13:00:00+00 | 2020-10-31 08:00:00 >> 8 | US/Central | 2020-11-03 | 08:00 | 2020-11-03 14:00:00+00 | 2020-11-03 08:00:00 >> 5 | US/Eastern | 2020-10-31 | 08:00 | 2020-10-31 12:00:00+00 | 2020-10-31 08:00:00 >> 6 | US/Eastern | 2020-11-03 | 08:00 | 2020-11-03 13:00:00+00 | 2020-11-03 08:00:00 >> (4 rows) >> >> What I actually need is, in example id=7, '2020-10-31 08:00:00-05'. >> >> Is this even possible? Several people have proposed that I write a custom function to do this on a per-row basis, which... I suppose I can do... I'm just blown away that this isn't something that just works "out of the box". >> > > Are you really asking what the TZ offset was on a specific date (Like DST or not)? > > > -- > Angular momentum makes the world go 'round. What it was at a specific date/time combination, yes. PostgreSQL already has that knowledge because of its ability to accurately calculate the value above in column "tswtz". It just doesn't seem to be able to output that easily. Though I just did realize that (obviously) I can do math to arrive at the answer I need. I'm perplexed by my not having realized that long before I considered creating this thread. -_- This is ugly and ineligant, but it seems to work: CASE WHEN ((timezone('UTC',(l.loc_date + l.loc_time::time without time zone)) - timezone(l.timezone, l.loc_date + l.loc_time::time without time zone))::interval) > '-00:00:01' THEN to_char((l.loc_date + l.loc_time::time without time zone),'YYYY-MM-DD HH24:MI:SS') ||'+'|| to_char((timezone('UTC',(l.loc_date + l.loc_time::time without time zone)) - timezone(l.timezone, l.loc_date + l.loc_time::time without time zone))::interval, 'HH24:MI:SS') ELSE to_char((l.loc_date + l.loc_time::time without time zone),'YYYY-MM-DD HH24:MI:SS') || to_char((timezone('UTC',(l.loc_date + l.loc_time::time without time zone)) - timezone(l.timezone, l.loc_date + l.loc_time::time without time zone))::interval, 'HH24:MI:SS') END AS correct_format --c175ebddb13b4992ad8f61e80f62d958 Content-Type: text/html Content-Transfer-Encoding: quoted-printable
At 2020-09= -27T19:13:09-04:00, Ron <r= onljohnsonjr@gmail.com> sent:
On 9/27/20 4:16 PM, aNullValue (Drew Stemen) w= rote:

Hello,

I've attempted to obtain help with this problem from several other places, but numerous individuals recommended I ask this mailing list.

What I need is for the ability to return a timestamp with timezone, using the UTC offset that corresponds to a column-defined timezone, irrespective of the client/session configured timezone.

I have three columns in a table:
Timezone: 'US/Eastern'
Date: 2020-10-31
Time: 08:00

The o= utput I'm able to find includes these possibilities:
'2020-10-31 08:00:00'
'2020-10-31 12:00:00+00'

Wherea= s what I actually need is:
'2020-10-31 08:00:00-05'

Using = the postgresql session-level timezone configuration won't work because I need multiple timezones to be handled in a single set.=

Example code follows. I'm not using to_char in the examples as I likely would= in the production code, but I haven't found any way that it could be helpful here regardless.

[snip]
=


id |  timezone  |  loc_date  | loc_time |      &= nbsp;  tswtz          = |       tswotz
----+------------+------------+----------= +------------------------+---------------------
  7 | US/Central | 2020-10-31 | 08:00    | 2020-10-31 13:00:00+00 | = 2020-10-31 08:00:00
  8 | US/Central | 2020-11-03 | 08:00    | 2020-11-03 14:00:00+00 | = 2020-11-03 08:00:00
  5 | US/Eastern | 2020-10-31 | 08:00    | 2020-10-31 12:00:00+00 | = 2020-10-31 08:00:00
  6 | US/Eastern | 2020-11-03 | 08:00    | 2020-11-03 13:00:00+00 | = 2020-11-03 08:00:00
(4 rows)
What I actually= need is, in example id=3D7, '2020-10-31 08:00:00-05'.
<= div style=3D"font-family:Arial;font-size:10px;">
Is this even possible? Several people have proposed that I write a custom function to do this on a per-row basis, which... I suppose I can= do... I'm just blown away that this isn't something that just works "out of the box".


Are you rea= lly asking what the TZ offset was on a specific date (Like DST or not)?


--
Angular momentum makes t= he world go 'round.

What it was at a specific date/time combination, yes. Postgr= eSQL already has that knowledge because of its ability to accurately cal= culate the value above in column "tswtz". It just doesn't seem to be abl= e to output that easily.

Th= ough I just did realize that (obviously) I can do math to arrive at the = answer I need. I'm perplexed by my not having realized that long before = I considered creating this thread. -_-

This is ugly and ineligant, but it seems to work:
<= div style=3D"font-family:Arial;font-size:10px;">
CASE WHEN ((timezone('UTC',(l.loc_dat= e + l.loc_time::time without time zone)) - timezone(l.timezone, l.loc_da= te + l.loc_time::time without time zone))::interval) > '-00:00:01' TH= EN
to_char((l= .loc_date + l.loc_time::time without time zone),'YYYY-MM-DD HH24:MI:SS')= ||'+'|| to_char((timezone('UTC',(l.loc_date + l.loc_time::time without = time zone)) - timezone(l.timezone, l.loc_date + l.loc_time::time without= time zone))::interval, 'HH24:MI:SS')
ELSE
to_char((l.loc_date + l.loc_time::time without time zone)= ,'YYYY-MM-DD HH24:MI:SS') || to_char((timezone('UTC',(l.loc_date + l.loc= _time::time without time zone)) - timezone(l.timezone, l.loc_date + l.lo= c_time::time without time zone))::interval, 'HH24:MI:SS')
END AS correct_format




--c175ebddb13b4992ad8f61e80f62d958--