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 1lpART-0007gj-5G for pgsql-novice@arkaria.postgresql.org; Fri, 04 Jun 2021 14:04:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lpARR-0005P1-9l for pgsql-novice@arkaria.postgresql.org; Fri, 04 Jun 2021 14:04:53 +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 1lpARR-0005HV-2P for pgsql-novice@lists.postgresql.org; Fri, 04 Jun 2021 14:04:53 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lpARK-0007Ev-Oy for pgsql-novice@lists.postgresql.org; Fri, 04 Jun 2021 14:04:52 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 154E4ekg144135; Fri, 4 Jun 2021 10:04:40 -0400 From: Tom Lane To: depesz@depesz.com cc: Jonas Gassenmeyer , pgsql-novice@lists.postgresql.org Subject: Re: NOW() function in combination with SET timezone In-reply-to: <20210604103557.GA31655@depesz.com> References: <20210604103557.GA31655@depesz.com> Comments: In-reply-to hubert depesz lubaczewski message dated "Fri, 04 Jun 2021 12:35:57 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <144133.1622815480.1@sss.pgh.pa.us> Date: Fri, 04 Jun 2021 10:04:40 -0400 Message-ID: <144134.1622815480@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk hubert depesz lubaczewski writes: > On Fri, Jun 04, 2021 at 09:53:20AM +0200, Jonas Gassenmeyer wrote: >> - Let's assume my client has set the timezone to Tokyo and the server is >> using UTC. >> - Even if calling NOW() and the display in my client is Tokyo time, once >> I send data to the server my timestamp would get converted to the timezone >> of the server. > Assuming you're talking about timestamptz - value on disk is in UTC. Yeah. There's no such thing as a "server timezone" for this purpose. (The server does have a "log timezone" setting, but that's for log messages; it shouldn't ever affect client-visible behavior.) The string you send to the server is assumed to be in the timezone defined by the client-controllable timezone setting, and it is converted to UTC for storage. (Of course, if the string you send contains an explicit zone name or UTC offset, we believe that instead; but in any case the bits on disk represent a time in UTC.) Later, if you try to read out the value, the value is converted to a string according to the then-prevailing timezone setting. Internal operations like now() and comparisons are unbothered by the timezone setting --- they just deal in UTC timestamps. > timestamptz doesn't store time zone information, This is the main thing you need to realize when coming to Postgres from another DBMS. It's not per SQL spec, I think, but we're unlikely to change its behavior at this late date. regards, tom lane