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 1kMe3A-0008QU-OM for pgsql-general@arkaria.postgresql.org; Sun, 27 Sep 2020 21:17:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kMe38-0004FM-0N for pgsql-general@arkaria.postgresql.org; Sun, 27 Sep 2020 21:17:38 +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 1kMe36-0004F2-5F for pgsql-general@lists.postgresql.org; Sun, 27 Sep 2020 21:17:37 +0000 Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kMe2z-0004y9-Ar for pgsql-general@lists.postgresql.org; Sun, 27 Sep 2020 21:17:35 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 28ECF5C011B for ; Sun, 27 Sep 2020 17:17:28 -0400 (EDT) Received: from imap8 ([10.202.2.58]) by compute3.internal (MEProxy); Sun, 27 Sep 2020 17:17:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anullvalue.net; h=mime-version:message-id:date:from:to:subject:content-type; s= fm1; bh=LITLg7PclHIzDOtGcUK1m31NBOMVWQwcZcgdv3DUMKs=; b=w1ZpfJsC IQea8xGj6eYF/5tVT8hoq7TSzXWGRKQJZIo/pK+YkDkhtH0Mi805v6+aQ6XtdMQB ObASBKPMLArqyvWmcg6T7x/HsLcEqf9+YnOCpGnMNsLD2e9X1/TtYiVHreIq4SHe ecpZmrB9McYBBk/DwQv//AtSEXVmsWWtD7pf80TZNrg/LzhqSU+TNwaR7z+gKYcf +iwYa3wY1c0Vy+6DEwQ4/qRdZUlZ3bl7YFp3VVmzwOeN+Evm7PAV8ZygZj+ouKlk OhXpDD432csoPSUdZmslRcvgka6BPoR3Nz6Bqj/SJcsC82rD/wSQTvWEDVHp14U5 pxl3xpIco1nNXQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:message-id :mime-version:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; bh=LITLg7PclHIzDOtGcUK1m31NBOMVW QwcZcgdv3DUMKs=; b=aitdn7nRophGaBefQfVFlq41yTUUMriQhVh7RCoOkyuYb bfTxboAb4c28hPo5eT2oVwpYN4lsEs3zYGXP339hJ/MWeLeuxX8wuaigiVINEza5 KDPehBiNK9ZzKuEWQUTP4I00/rznZR2RY3poDwqJpZ9IBcSiRbnYhO8UUpQS/IRt VVVOWhw2qaUfvF5ryo4IuAmk2vSRRueETg9tQ62KpW4g2SIUWTlGsiJMcF/pQl+N baJynGTclsgOCLDiD7UM7yCDURUTVFD0dqCtuk5cKHdg5GrystRFge2Wi3l8XNNY ojBavkkOPZIWNuS0oTb8MYDlinznMQFYc7zP1o7uQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrvdeggdduiedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefofgggkfffhffvufgtsegrtderre erreejnecuhfhrohhmpedfrgfpuhhllhggrghluhgvucdlffhrvgifucfuthgvmhgvnhdm fdcuoegurhgvfiesrghnuhhllhhvrghluhgvrdhnvghtqeenucggtffrrghtthgvrhhnpe euiefgkeeufefgkedtveeffefgveehgfehieejiedtgeehvdfhgfdtueeifeegheenucev lhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegurhgvfiesrg hnuhhllhhvrghluhgvrdhnvght X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 98E53520094; Sun, 27 Sep 2020 17:17:27 -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: <3af9fdd2-b622-426a-8e1e-aeab1bee8493@www.fastmail.com> Date: Sun, 27 Sep 2020 17:16:54 -0400 From: "aNullValue (Drew Stemen)" To: pgsql-general@lists.postgresql.org Subject: =?UTF-8?Q?Returning_timestamp_with_timezone_at_specified_timezone_irresp?= =?UTF-8?Q?ective_of_client_timezone?= Content-Type: multipart/alternative; boundary=f03b8773d7eb44489115d2c4acb1cf1f List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --f03b8773d7eb44489115d2c4acb1cf1f Content-Type: text/plain 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. --------------------------------------------------- SET TIME ZONE 'UTC'; CREATE TABLE loc ( id serial not null, timezone text not null, loc_date date NOT NULL, loc_time text NOT NULL, CONSTRAINT loc_pkey PRIMARY KEY (id), CONSTRAINT loc_loc_time_check CHECK (loc_time ~ '(^(2[0-3]|[01][0-9]|[0-9]):?([0-5][0-9]):?([0-5][0-9])?$)|(^(1[012]|0[1-9]|[1-9]):[0-5][0-9] [AaPp][Mm]$)'::text) ) ; INSERT INTO loc (timezone, loc_date, loc_time) VALUES ('US/Eastern', '2020-10-31', '08:00'), ('US/Eastern', '2020-11-03', '08:00'), ('US/Central', '2020-10-31', '08:00'), ('US/Central', '2020-11-03', '08:00'); SELECT * , timezone(l.timezone, l.loc_date + l.loc_time::time without time zone) tswtz , (l.loc_date + l.loc_time::time without time zone) tswotz FROM loc l ORDER BY timezone, loc_date, loc_time ; --------------------------------------------------- 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". --f03b8773d7eb44489115d2c4acb1cf1f Content-Type: text/html Content-Transfer-Encoding: quoted-printable
Hello,

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

What I need is for the ab= ility to return a timestamp with timezone, using the UTC offset that cor= responds to a column-defined timezone, irrespective of the client/sessio= n configured timezone.

I ha= ve 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:0= 0:00'
'2020-10= -31 12:00:00+00'

Whereas wh= at I actually need is:
'2020-10-31 08:00:00-05'

Using the postgresql session-level timezone configuration won't w= ork 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.

-----------------------------= ----------------------

SET = TIME ZONE 'UTC';

CREATE TAB= LE loc
(
    = id serial not null,
timezone text not null,
    loc_date date NOT NULL,
    loc_time= text NOT NULL,
    CONSTRAINT loc_pkey PRIMARY KEY (id),
    CONSTRAI= NT loc_loc_time_check CHECK (loc_time ~ '(^(2[0-3]|[01][0-9]|[0-9]):?([0= -5][0-9]):?([0-5][0-9])?$)|(^(1[012]|0[1-9]|[1-9]):[0-5][0-9] [AaPp][Mm]= $)'::text)
)
;

INSERT INTO loc (timezone, loc_date, loc= _time) VALUES
= ('US/Eastern', '2020-10-31', '08:00'),
('US/Eastern', '2020-11-03', '08:00'),
('US/Central', '2020-1= 0-31', '08:00'),
('US/Central', '2020-11-03', '08:00');

SELECT *
, timezone(l.timezone, l.loc_date + l.loc_time::time without t= ime zone) tswtz
, (l.loc_date + l.loc_time::time without time zone) tswotz
FROM loc l
ORDER BY timezone, loc_date,= loc_time
;

-----------------------------= ----------------------

id |=   timezone  |  loc_date  | loc_time |  &nb= sp;      tswtz     &nb= sp;    |       tswotz
----+------------+-= -----------+----------+------------------------+---------------------
  7 | US/Ce= ntral | 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    | 202= 0-11-03 14:00:00+00 | 2020-11-03 08:00:00
  5 | US/Eastern | 2020-10-31 | 08:00&n= bsp;   | 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-1= 1-03 08:00:00
= (4 rows)

<= /div>
What I actually ne= ed is, in example id=3D7, '2020-10-31 08:00:00-05'.

Is this even possible? Several people have propos= ed 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 th= at just works "out of the box".

--f03b8773d7eb44489115d2c4acb1cf1f--