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 1kMgJp-0006KL-On for pgsql-general@arkaria.postgresql.org; Sun, 27 Sep 2020 23:43:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kMgJo-0008Rk-O3 for pgsql-general@arkaria.postgresql.org; Sun, 27 Sep 2020 23:43:00 +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 1kMgJo-0008Rd-C9 for pgsql-general@lists.postgresql.org; Sun, 27 Sep 2020 23:43:00 +0000 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kMgJm-0004l3-Op for pgsql-general@lists.postgresql.org; Sun, 27 Sep 2020 23:43:00 +0000 Received: by mail-pj1-x102c.google.com with SMTP id u3so2530421pjr.3 for ; Sun, 27 Sep 2020 16:42:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ardentperf-com.20150623.gappssmtp.com; s=20150623; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=s/jnoePwj53CcUfqh0nnmXjZDqRhpg1VVtaLB9jgqMk=; b=eBW7vHYqODOG0/iovloo9T3TvjDCeAPsSauHq7fwuDWcFYICVYbJA4MLqbRLfyceEg TYPBoWg8uZxV9RqcooeOsnE8RscQbYpgOZWM32TpBBI/rI8s/SVH6TlDTEiLMPE95q78 d+zAwdgpQcsh3QKyxDtloWcrMQzgfGaxuhQ02KnPabxnJVofNscYr8pR03jILiPsZyTG 9zQcr+Vg9/90HJrZH9FPKKp11GzP6DrQ14rYDrfB9AN+BOCDi92DaVhkHgBXHLoY4V/p br3PPwVXtXGDa+bjKtPPkc+BYGKe4RaSp+NWfpQRdmFDb+EGGEJ2okWOGeUeef2JyMtT YiEA== 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 :content-transfer-encoding; bh=s/jnoePwj53CcUfqh0nnmXjZDqRhpg1VVtaLB9jgqMk=; b=F0H2ZTtMy2x9n5zWrNJYe2WSbZV8/SnDIOYtGnt7C6xyjP6rGHLfmUzeuWjd1KxnYp v+W59MQLoJYu0198QqUzc63OlFJl9AnFTUTq8ZfmU6mB3nBJJjWGnv60q3LA6nRWCYvY Aw48ZZVsnIXSNnCzNogom5mIUPAV3h6gNZou7PHFSnfX9yPmIACrSr415B97sPLetJjx 5Kg4vnhxSibl08sQPCn4MjZZ5deSouTd0oZR9M7Z0jO96V628dBYpFrR09RT/yXFpJ4/ ggWDPGEGEZ4vM2CGc4l/4WGknTZfOR5+elg1I3BHCDZa/R1+03ITqbP1ksi/xK2pK4k5 wqxg== X-Gm-Message-State: AOAM531xbiCcrOZQq9NMnemP+4zRs/C7LdyD/Yiraw+7o4o9fJw76jvl 5/PqKCxTxGlzzDey99JjfO4WlG87DnigKQ== X-Google-Smtp-Source: ABdhPJxlc7OZaRxKjlsk9FLaq2R0H23GxbYdV3CiQ1pwh20Tzg/rBDPxhp+EZrec2KxzBePomGyNAw== X-Received: by 2002:a17:90a:e815:: with SMTP id i21mr6915321pjy.97.1601250175335; Sun, 27 Sep 2020 16:42:55 -0700 (PDT) Received: from 186590ce269b.ant.amazon.com ([54.240.196.175]) by smtp.gmail.com with ESMTPSA id s2sm358020pjg.52.2020.09.27.16.42.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 27 Sep 2020 16:42:54 -0700 (PDT) Subject: Re: Returning timestamp with timezone at specified timezone irrespective of client timezone To: Ron , pgsql-general@lists.postgresql.org References: <3af9fdd2-b622-426a-8e1e-aeab1bee8493@www.fastmail.com> <6b269cb9-5572-acaa-de9c-fe1c705fed11@gmail.com> From: Jeremy Schneider Message-ID: Date: Sun, 27 Sep 2020 16:42:53 -0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: <6b269cb9-5572-acaa-de9c-fe1c705fed11@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 9/27/20 16:13, Ron wrote: > On 9/27/20 4:16 PM, aNullValue (Drew Stemen) wrote: >> 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. > > Are you really asking what the TZ offset was on a specific date (Like > DST or not)? IIUC, there is a gap here in PostgreSQL. i think it could most easily/quickly be addressed with an overloaded version of to_char that accepts a "display timezone" for its timestamp to character conversion. FWIW - in Oracle this is handled by having two different data types: 1) TIMESTAMP WITH TIME ZONE 2) TIMESTAMP WITH LOCAL TIME ZONE ironically, oracle's "local" data type is the equivalent PostgreSQL's timestamp with time zone where the timestamp is converted and processed/stored without a time zone. afaik postgresql doesn't have a native data type equivalent to the first variant in oracle, which actually considers the time zone as part of the data. (am i missing something?) in lieu of having built-in support, a PL/pgSQL function to set the session-level timezone in between processing each record is the best approach i've thought of so far. -Jeremy -- http://about.me/jeremy_schneider