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 1mSmYO-0004b6-Es for pgsql-general@arkaria.postgresql.org; Tue, 21 Sep 2021 20:39:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mSmYM-0000cb-7m for pgsql-general@arkaria.postgresql.org; Tue, 21 Sep 2021 20:39:46 +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 1mSmYL-0000cT-IZ for pgsql-general@lists.postgresql.org; Tue, 21 Sep 2021 20:39:45 +0000 Received: from mail-ed1-x533.google.com ([2a00:1450:4864:20::533]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mSmYH-0003GO-Pj for pgsql-general@postgresql.org; Tue, 21 Sep 2021 20:39:44 +0000 Received: by mail-ed1-x533.google.com with SMTP id v22so1082403edd.11 for ; Tue, 21 Sep 2021 13:39:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=DWmMFrCljXPhc26A6Lq5OXiTPbtE0h+glNJwscNSLNY=; b=DYy2Qn7TLVuiCLKpushSZuAsCTs8iBMnpp7Mvph+tnAGmOmoGvtFoFQ9C/1UQ9mA3c G5dD+Bweq4JdiELm+4P0nzjnHT250Jc/uvoe8HMWgD/H3oR4qafjCvZrWEgEqx/4Qefw oLkScGJA0ZoTb67j/kLN8BKIOJzz4NxzWRNvRoQOyGmlKWW4j5G6+DJkxilu2cV292cx Jp8xIUgsKnRgZfI5dvNYwR8eyrbtHNLKWg9/51uaWT8ARZYruynQzXL6KRkYe8+psYYj IiMqY7Xm2PUd2Sf/23D6Y+e+iGWcOJuf2t3ooCdKMHiciFbymi/OoE5iilRKDevOIdEF Sc5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=DWmMFrCljXPhc26A6Lq5OXiTPbtE0h+glNJwscNSLNY=; b=TV8JnUQXDmnVDDiQAuDCEJTw7KG5VPwTpc80+STvhzv8l/QTMPTijFBPzxBnmGMnlQ 49GyEZcYmUsIxVhCGk61XR+Zp3TwWBOjZ5CBI7DOrgcjI/WXPhz7R02HNyTSe4vTVbyJ MGKGrf8esXPiEGJ6wx0eZjIQ9Uc/NS2MTqN3x8eH57H5LepHb6Btq79emVW96SpALseo LDuomG9jd4/6PEUcH9bo6XasZ/ERe0vRlY+bSbX+xifTPPLbYBfBOUvFzS03pETQ2VNy WM7YaCdkJJ1S+BANIHnKQWGtvPiVah52kWW3hfpa3ac3bnz8Rl1cm9Mah0xzENgxhqnk wRWg== X-Gm-Message-State: AOAM532KSfKIWSafEf3zM4OviQ2c1XmkWmvFmEkCowqkLNB7HUvlsiO4 tkFcuRfgGBN8gJcC+Wy9ai+KjiqUgWs= X-Google-Smtp-Source: ABdhPJx9hyuUwJ/xW6JrYtiKPZZD1mQoxHIAS282rEqkaRPKRmiPwTUYyAxcGfH3VrRdaBA3orxQsg== X-Received: by 2002:a17:906:ccca:: with SMTP id ot10mr36328765ejb.429.1632256779606; Tue, 21 Sep 2021 13:39:39 -0700 (PDT) Received: from localhost.localdomain (89-212-233-220.dynamic.t-2.net. [89.212.233.220]) by smtp.gmail.com with ESMTPSA id dc8sm9344edb.28.2021.09.21.13.39.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 21 Sep 2021 13:39:39 -0700 (PDT) Subject: Re: Timestamp with vs without time zone. To: Tim Uckun Cc: pgsql-general References: From: cen Message-ID: Date: Tue, 21 Sep 2021 22:39:38 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk From my experience, and some might disagree, I prefer to do db stores purely in UTC and handle timezones in ORM or client side. The only time I actually needed to store timezone information in a dedicated column is when needing to convey that information to the end user, for example "your plane will arrive at this date and time in this destination timezone". The majority of other cases are just a localization issue and don't require you to store the timezone info. Having to rely on database to muck around with timezones or doing it in session settings (which some advocate) is just asking for trouble in my opinion. On 9/21/21 9:35 AM, Tim Uckun wrote: > It seems like it would be so much more useful if the timestamp with > time zone type actually stored the time zone in the record. > > > On Tue, Sep 21, 2021 at 7:25 PM Laurenz Albe wrote: >> On Tue, 2021-09-21 at 18:00 +1200, Tim Uckun wrote: >>> I am hoping to get some clarification on timestamp with time zone. >>> >>> My understanding is that timestamp with time zone stores data in UTC >>> but displays it in your time zone. >> That is correct. >> When a timestamp is rendered as string, it it shown in the time zone >> specified by the current setting of the "timezone" parameter in your >> database session. >> >>> Does this also work on queries? If >>> I query between noon and 2:00 PM on some date in time zone XYZ does pg >>> translate the query to UTC before sending it to the server? >> Yes. >> >>> To provide context I have the following situation. >>> >>> I have a data file to import. All the dates in the time zone >>> pacific/auckland. My app reads the data , does some processing and >>> cleaning up and then saves it to the database. >>> >>> The language I am using creates the time data type with the right time >>> zone. The processing is being done on a server which is on UTC, the >>> database server is also on UTC. I am pretty sure the ORM isn't >>> appending "at time zone pacific/Auckland" to the data when it appends >>> it to the database. >>> >>> So does the database know the timestamp is in auckland time when the >>> client is connecting from a server on UTC? >> It does, but only if you set "timezone" appropriately in the database >> session. You could use ALTER ROLE to change the default setting for a >> database user, but it might be best to set that from the application. >> >> Yours, >> Laurenz Albe >> -- >> Cybertec | https://www.cybertec-postgresql.com >> >