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 1jOqDK-00045X-Fr for pgsql-general@arkaria.postgresql.org; Wed, 15 Apr 2020 22:08:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jOqDJ-0006Wh-3Y for pgsql-general@arkaria.postgresql.org; Wed, 15 Apr 2020 22:08:57 +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 1jOqDI-0006Wa-P2 for pgsql-general@lists.postgresql.org; Wed, 15 Apr 2020 22:08:56 +0000 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jOqDC-0007Qy-7G for pgsql-general@lists.postgresql.org; Wed, 15 Apr 2020 22:08:55 +0000 Received: by mail-pg1-x542.google.com with SMTP id t11so622010pgg.2 for ; Wed, 15 Apr 2020 15:08:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=references:user-agent:from:to:subject:in-reply-to:message-id:date :mime-version; bh=ytXi1N/3jgbrvVW2aAXFwGhLX/XKMNdtB/90SUmspng=; b=d7x0l0OVsQC4gacs965dnukHJ8H194PWb7BJte3Z+H/1G7sJNYTfn2/W9Rkpt/jEv8 W1bchX8NUWbiYeNFL80eJ9ZFjFax/LyUEXmFdkahNtjQN+tnygHArPJBZTyj7fU5Jb7y VwFqY5Rag1Mo0lBw+QTeq2WLMKO1tP2VjOkNrC2i4aSm3DkJL9py6ZAlGlwOiKbo6IMY PQ7Ejdyf9m/kP6SupbIkCu26Lm84nYAWLgYjYJhbk6Xsi3hZ/Uh4dLGUiQelTpILT8kR saq5Kg8nLDXB9IXkVgpQ2mL1ZGn++kAf9jrwtE9G/ZCBpt8qQRLz6BCA/mjVOKxsI5w2 U0kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:references:user-agent:from:to:subject :in-reply-to:message-id:date:mime-version; bh=ytXi1N/3jgbrvVW2aAXFwGhLX/XKMNdtB/90SUmspng=; b=c4oIx+QItv9K/vrIIHJfuyXkLMNstMG+KeVsq25Z9AWlR1lwcahTWy7zp2CRJYIAH1 AqpN3nvuE31ysFZnte3FIlzel4zi16yEcUkRIrKZ9AYZqIUPheGOMdy0GBcVC78LeRdE 4dMD6gQY6kHcyf9DDZ9AnRzfMkGdImBnXnhitoAfOYyEYKqnMUAvpJxA3ZsSW4W58sPn RbXf/UrttuZuawbUp766TEtbkiWD9n1PXX3+2aWHTIPiRzOAt/pfK15JRtjAy8a8mdv7 8TzAgNef+10MRu3v66WIa3UpQDGrIPwC0SBMjLkEGTiwUue8+4oFm9bwnAFqOaEJP1Zq 3nMw== X-Gm-Message-State: AGi0PuYJFNE46J+JZz405Dr9wSarVpU5Qj3dCnrQkGMgLE1Z3dl1tbLB Cx8ViBXPWhWxKeCyYSbX7n/4nHTs X-Google-Smtp-Source: APiQypJQOxRkiMsQeQ1xISZChNbUSgWHGXvHynQqMuC2eKpj9B7UgknlUXDh333+WXZPiGimTi67Bg== X-Received: by 2002:aa7:9218:: with SMTP id 24mr12404714pfo.312.1586988528482; Wed, 15 Apr 2020 15:08:48 -0700 (PDT) Received: from tim-desktop (203-173-23-138.dyn.iinet.net.au. [203.173.23.138]) by smtp.gmail.com with ESMTPSA id f70sm2726449pfa.17.2020.04.15.15.08.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Apr 2020 15:08:47 -0700 (PDT) References: <4757e6ae98474a2897b2fac202466e5e@dst.dk> User-agent: mu4e 1.3.10; emacs 27.0.90 From: Tim Cross To: pgsql-general@lists.postgresql.org Subject: Re: timestamp and timestamptz In-reply-to: <4757e6ae98474a2897b2fac202466e5e@dst.dk> Message-ID: <87pnc8ieqa.fsf@gmail.com> Date: Thu, 16 Apr 2020 08:08:45 +1000 MIME-Version: 1.0 Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Niels Jespersen writes: > Hello all > > > > We have some data that have entered a timestamp column from a csv. The data in the csv are in utc. We want to access the data in > our native timezone (CET). > > > > I am considering a few alternatives: > > > > 1. Early in the process, convert to timestamptz and keep this datatype. > > 2. Early in the process, convert to timestamp as understood in CET. This will imply by convention that the data in the timestamp > column represents CET. Users will need to be told that data represents CET, even if data is somwhere in the future kept in another > country in another timezone. > > > > I probably should choose 1 over 2. But I am a bit hesitant, probably because we almost never have used timestamptz. > > > > Can we agree that the below query is selecting both the original utc timestamps and 2 and 1 (as decribed above)? > > > > set timezone to 'cet'; > > select read_time read_time_utc, (read_time at time zone 'utc')::timestamp read_time_cet, (read_time at time zone 'utc')::timestamptz > read_time_tz from t limit 10; > > > > We are on Postgres 12. > > > Keep your life simple - just go with option 1. Keep all timestamps in UTC and let clients deal with it in whatever way they need to. This will also help deal with issues associated with daylight savings time (DST can be a real pain as different locations have it and others don't and the 'switchover' date is subject to political whims and can change). Your option 2 will cause all sorts of issues and keep in mind that most larger countries have multiple timezones, so even if your data is all associated with a single country, you can potentially have multiple conversion routines required. On most *nix systems, clock time is UTC as well, so having everything in UTC really helps when you want to do diagnosis across your database and system log files etc. -- Tim Cross