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.96) (envelope-from ) id 1vxOtM-00C7nv-1Z for pgsql-general@arkaria.postgresql.org; Tue, 03 Mar 2026 12:30:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vxOtK-0071jT-2x for pgsql-general@arkaria.postgresql.org; Tue, 03 Mar 2026 12:30:23 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vxOtK-0071jL-1o for pgsql-general@lists.postgresql.org; Tue, 03 Mar 2026 12:30:23 +0000 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vxOtI-00000000BEN-20DB for pgsql-general@lists.postgresql.org; Tue, 03 Mar 2026 12:30:22 +0000 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-48378136adcso33151585e9.1 for ; Tue, 03 Mar 2026 04:30:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1772541019; x=1773145819; darn=lists.postgresql.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:from:to:cc:subject:date :message-id:reply-to; bh=iSvdPHdsfpesV+X7U4o8yyQgDgzw0ncAtN67Tov7Xs0=; b=cnLqBnsEucoaamiowzEajFoGssfNDCM1Y7LYqq5w+vdug9JyTPHLa4+dArw7ey5qCV rQYAlHcARhFCMg1HG44nAmnHYbZEB/dBGNAvcVj1UOeHNzO8WpSlqBlve6XaHIwugaPl XYlSg2uxS8aa2uKynXWT9/5TKTmyqZYG1SbBMBuBqNs771Gl9uMzU7Lh1I9nebuGe0+k KDsrrWEhKDJRtl2LKCliPUrv1dgWzIIG6Fm++nfQaaZVWo9JYK2GsJpq/SLLLqRU3Pqk aPTOjPc3PIfFzEIMcr3UaLveXwTo5ts1FWrqp8+qAyXspW0Nln3brMyxLs8jtNkaB+mG 6Mng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772541019; x=1773145819; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=iSvdPHdsfpesV+X7U4o8yyQgDgzw0ncAtN67Tov7Xs0=; b=qda0lI+rZEijT1zruqfsJmT7o9wCO7GNwOKoMN9CuOIl/7VNqOVTkDfVxvLnLdZj8j zzcQyxo9xC/RJD0x1SCI/dq1WJQrYk1z7K/8LPSnT9RHHGTUttyB/w2reXOlHOsYfSL2 cPJQ7dRqUJsFlIbrZWrqEBM7umBugad3X41aaUZ4IeDTcC0jSj4c3bRuq2BPd1DIARlw xQFcHeuiuC5QsAXvGW9OqDltSl1PzXHfboNKOoVhtFWUsur65IWeVLKBE8lAR6Peyl29 tkeiMmUZB08KmILeDS+HIMBKuXwcwbNXG44j+8LE8oNbLZ1zSEtcHzvzW1EP8cr/QnRk yMpA== X-Forwarded-Encrypted: i=1; AJvYcCWihoASir/6OLj4Wn5x6NnvAbEb5jZovkOrP4/0JZ88EdN/Cslf9UZ9H7wDDWTbZ4dY4s4y4cqLF7T/M735@lists.postgresql.org X-Gm-Message-State: AOJu0YyCCmlRNfGCO13JmvH1yIqsQsCf9NixCFVJ2/LJVAGsnaQs+T7B utvYSCaNpPnT75bZOZkFGlRgH5Zqz8g8HesrGYA43ocboFPUbNazx8Ch3x6aJKHE9Kg= X-Gm-Gg: ATEYQzyWlZKajuvKTCISh+EY7wb3eFdj3GIkrLZqIBTts+9846ca+WsPFq76TO/kdfz bryQgMtVRphMc619RHTyIznF/dG0EH2aFNwo5HxYveLhYxTh/NhB7zaRQvGlVjnBvsrN3ISr9Eb 9V53iuKaMtY08QTyH/At3L8opa8UZp0MpW3kFqwIs2Lh08bVwhXzZHkotCH8JLTCFN7d6DwvopH HTeHkDxGAz6VCpMUwqIasWfBkm0bJa25BJS1DtF7gnijw69EYpQV3Xw7LhhtBucNtw424Yjatwm /XuUhXsOaCKvJQ5A7rB7Hk4//xJmxSO2iZWREggvxygayEJux3kiK8c1uFOsgSACdMUyuotKxWJ 3aQorOnn+WENoA5iEXxphD5fwOIgYk/aGloZmYAxDCgVJdTemQEYB39okWxi7YeWmGdP+EqPR1D 7wbhTuOh9WtmgKmZ/eUNvpUXcsSODdxER4gG2XoGFW+h4ZwGXg8rx6 X-Received: by 2002:a05:600c:1548:b0:480:1c10:5633 with SMTP id 5b1f17b1804b1-483c9c1045cmr277018915e9.26.1772541019074; Tue, 03 Mar 2026 04:30:19 -0800 (PST) Received: from laurenz.albe-K4N0CV00F97414D ([2001:871:70:68a9:f22f:eefb:ae52:d37a]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-483c3b4a121sm339106265e9.8.2026.03.03.04.30.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Mar 2026 04:30:18 -0800 (PST) Message-ID: <68be1c2b7bcdbe3c110ee407ac6bbcf4f56df94a.camel@cybertec.at> Subject: Re: Timezone handling with timestamp without time zone columns From: Laurenz Albe To: Nandish Bhuva , "pgsql-general@lists.postgresql.org" Date: Tue, 03 Mar 2026 13:30:17 +0100 In-Reply-To: References: <8c3b8558fc3322c31d9f05517dcdb43e16296fa0.camel@cybertec.at> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.58.3 (3.58.3-1.fc43) MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, 2026-03-03 at 10:10 +0000, Nandish Bhuva wrote: > As mentioned previously: > =C2=A0* empjob_utc_update_date=C2=A0stores UTC values (but is defined as = timestamp without time zone) > =C2=A0* jstsk_lst_end_tm=C2=A0stores Canada/Pacific local time (also time= stamp without time zone) > > Our goal is to convert both timestamps to a common timezone (for example,= UTC) within the query itself to ensure accurate comparison. > I attempted the following: >=20 > =C2=A0=C2=A0=C2=A01.=20 > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0SELECT > =C2=A0 =C2=A0 (to_timestamp('2026-02-19 01:23:46.016', > =C2=A0 =C2=A0 'YYYY-MM-DD HH24:MI:SS.FF3') > =C2=A0 =C2=A0 AT TIME ZONE 'Canada/Pacific') > =C2=A0 =C2=A0 AT TIME ZONE 'UTC' AS utc_time; to_timestamp() returns a "timestamp with time zone", so that won't work. > =C2=A0=C2=A0=C2=A02.=20 > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0select ej.empjob_utc_update_date=C2= =A0, > (SELECT jstsk_lst_end_tm=C2=A0AT TIME ZONE 'Canada/Pacific' = AT TIME ZONE 'UTC' > FROM jobskd_task > WHERE jstsk_desc=C2=A0=3D 'ALERT - VCH - Team approver Chan= ges' > AND jstsk_deleted=C2=A0=3D 'N' > order by jstsk_lst_end_tm > desc > limit 1) as job_last_run_time > from employee_job ej > where ej.empjob_utc_update_date=C2=A0>=3D (SELECT jstsk_lst_end_tm > FROM jobskd_task > WHERE jstsk_desc=C2=A0=3D 'ALER= T - VCH - Team approver Changes' > AND jstsk_deleted=C2=A0=3D 'N= ' > limit 1) The timezone conversion is done correctly, provided that "jstsk_lst_end_tm" is really of data type "timestamp without time zone" and has "Canada/Pacifi= c" time stored. > However, the result does not appear to be converting correctly in our act= ual comparison scenario. Please be precise. What is the value stored, the value that the query returns, and what is what you would consider the correct value? > Could you please advise on the correct way to: > =C2=A0=C2=A0=C2=A01. Treat empjob_utc_update_date=C2=A0explicitly as UTC > =C2=A0=C2=A0=C2=A02. Treat jstsk_lst_end_tm=C2=A0explicitly as Canada/Pac= ific How do you treat a "timestamp without time zone" as UTC? Please be specific. > =C2=A0=C2=A0=C2=A03. Convert both to the same timezone (e.g., UTC) within= a SELECT=C2=A0query That's what I showed you, and what you say is not correct. > =C2=A0=C2=A0=C2=A04. Compare them accurately without modifying stored dat= a jstsk_lst_end_tm AT TIME ZONE 'Canada/Pacific' AT TIME ZONE 'UTC' =3D empjo= b_utc_update_date Yours, Laurenz Albe