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 1kMfr7-00054J-R0 for pgsql-general@arkaria.postgresql.org; Sun, 27 Sep 2020 23:13:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kMfr5-0003rJ-1f for pgsql-general@arkaria.postgresql.org; Sun, 27 Sep 2020 23:13:19 +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 1kMfr4-0003rC-Iq for pgsql-general@lists.postgresql.org; Sun, 27 Sep 2020 23:13:18 +0000 Received: from mail-oi1-x22e.google.com ([2607:f8b0:4864:20::22e]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kMfqy-0005u0-2a for pgsql-general@lists.postgresql.org; Sun, 27 Sep 2020 23:13:17 +0000 Received: by mail-oi1-x22e.google.com with SMTP id x69so9590375oia.8 for ; Sun, 27 Sep 2020 16:13:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language; bh=k20L0OICK3zjQMiF4yMFUBVEJsutFGf1zYpq6hcwzWY=; b=Q9wZA5EhzDwMbE7nAU2q8W7qT3jE+X7v3HciGhkzzOvzmDcJIVuA3O1IGy/TL8s1Qd Ng9nFlVEbigJij7pePrEWPoZmxss5eIypSpIe0uWbfW572116SiGbhNyPk7lTqERSwi0 sF+HRrXeaKYFO5xovOOPvhJgQX56HarudwFCGLdwX93hZz/PAWZWaHykpqncL9WIHSjJ gLwofn51Wj+ymqGMakSBvm1omm2EyWj5oTu8PInBnSpK0jwBoLw6xsm7vtwZ3LDWwA+O KHFpu5JppTsU1/S/dO+eO0Z1JqlY2Dw0qo0AEPymdb8bTNmrkU0M9qx36bgMcDf2d55i o4VA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=k20L0OICK3zjQMiF4yMFUBVEJsutFGf1zYpq6hcwzWY=; b=KgjYewHgN7aYyRd5aE3vAaWafec1pFwOrda3wEYRiYbA3wzbi2+mKJNXi2PEJEUm3e A3Zt75eFBRFuB9X1L/1dVGvjsGSO3rUjf2MzydH2VfZuOGQLbAiZlTd7ruBumWsObmsO sxutvQ4r6QilGgvCR4YpUnOXxvtfYIQPCDNiOf8r71bS5YxIscqBTuXnMasWEuyNXjiw F+jVRsrBF7Sp0hsBHTzKkaN9O8e8+H6raLLhx0CHYDzhL06XryERRP1QHa++ra7+oyC4 oBS5T8YbLVWZVlW8JsgtEn52anv0rljZRK1/ICm3WEJdqZCf1rFj+3c0St7YDShAJrKo Ic7A== X-Gm-Message-State: AOAM531mbjNqy9olMeIfC+dcbvem2pc6GPxatQeengfg0/HOGC6fR/v1 +fiI9p3ko6gMCZgfTO0pd0QjzGptdwRHvg== X-Google-Smtp-Source: ABdhPJy8iq2OTkl2LJkkkTzUd4cV4GD4akf6Gqtz80I7IJFZmU3HBRPbUnOc+FEmDiNAkXcsgwU8WQ== X-Received: by 2002:aca:ef84:: with SMTP id n126mr4143504oih.123.1601248390555; Sun, 27 Sep 2020 16:13:10 -0700 (PDT) Received: from [192.168.1.10] (ip174-67-143-111.no.no.cox.net. [174.67.143.111]) by smtp.googlemail.com with ESMTPSA id q14sm2462398ota.41.2020.09.27.16.13.09 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 27 Sep 2020 16:13:09 -0700 (PDT) Subject: Re: Returning timestamp with timezone at specified timezone irrespective of client timezone To: pgsql-general@lists.postgresql.org References: <3af9fdd2-b622-426a-8e1e-aeab1bee8493@www.fastmail.com> From: Ron Message-ID: <6b269cb9-5572-acaa-de9c-fe1c705fed11@gmail.com> Date: Sun, 27 Sep 2020 18:13:09 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <3af9fdd2-b622-426a-8e1e-aeab1bee8493@www.fastmail.com> Content-Type: multipart/alternative; boundary="------------E533FE419D32DCCCD40B3C47" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------E533FE419D32DCCCD40B3C47 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit 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. --------------E533FE419D32DCCCD40B3C47 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit 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.
--------------E533FE419D32DCCCD40B3C47--