Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fdMiT-0004Z6-AL for pgsql-general@arkaria.postgresql.org; Wed, 11 Jul 2018 21:32:05 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fdMiR-0004sR-4e for pgsql-general@arkaria.postgresql.org; Wed, 11 Jul 2018 21:32:03 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fdMiQ-0004sK-PQ for pgsql-general@lists.postgresql.org; Wed, 11 Jul 2018 21:32:02 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fdMiJ-0005iv-KB for pgsql-general@postgresql.org; Wed, 11 Jul 2018 21:32:01 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 24BEC21448; Wed, 11 Jul 2018 17:31:54 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Wed, 11 Jul 2018 17:31:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; bh=riNpiHnFK2Ri215ZWgdP3cIqD2IMZ l811IjdaSatDRo=; b=C1q/rdaqePXAFqdXE3wVFCBnhJDq/lvBykCjMo3CHUzz4 Ct+ceunP24374us6lELmJyBFT8p+I/gUi7fxvE5PtX94vurXlJfLxkhHburmeDS5 lpcAJ0wm7/1IQZ1EenHvzPqv0O86pAiQG+GVHNmPx3iGkAsvQ5NFTAjYFIPYAotR WBatfvnhBoUimkvYsfeSvSXlgV7D6yFfVBWfZQzeCsU2hAQEWG/2Q/txK0lcyR/E 5DH+8eJmyyMDNOrYRDQ+NTiblfQNznGxCmu7Mf7EVcvfxUhIzvtDLzlvQQi7rcSC +wakr9cKk8ZK4rYciCE1zPIOrgsaCJUzrus9UC18g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=riNpiH nFK2Ri215ZWgdP3cIqD2IMZl811IjdaSatDRo=; b=NyZVu3VM/7H+bwW1ALDFlC UmwSOdV7SW+vZsebWGDCHefOCYQbQ8QZvXBXbQdTsRdb9C+eYiAZNVqNvm6W2fYH EOZ7PoeYRmPikkM8EeUhw5P8qq1/kHOoRnQjfKHtFTaVhRZujZCDts38YBf56TYO tNUQphkhHQbuL8/jznrj6X6h4TGFMBvk/c+dkLhmlKutRf6WyRMNUz5QAdTpYyJb ON/GiR81/yBqvZ7Wm4rSkGibFBkNlDx+RFbMbPsM4kFc77wtV8Ns9guh7qJYXUn1 6nFeO2O6KjskO36JwUXGuR7+bOgq3hv5Vz8flZVOfbdBiFLWhmNaFin/nThxxtSQ == X-ME-Proxy: X-ME-Sender: Received: from ranger.suse (unknown [74.94.73.222]) by mail.messagingengine.com (Postfix) with ESMTPA id 509B410261; Wed, 11 Jul 2018 17:31:53 -0400 (EDT) Subject: Re: timestamp (military) at time zone without the suffix To: David Gauthier References: <84450581-6f59-cf88-ee2c-eaa03f9bba87@aklaver.com> Cc: pgsql-general From: Adrian Klaver Message-ID: <652f88fe-af0f-4f9c-0ef1-ee814b8a05ac@aklaver.com> Date: Wed, 11 Jul 2018 14:31:52 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 07/11/2018 02:21 PM, David Gauthier wrote: Pleas reply to list also. Ccing list. > Table columns have already been defined with timestamp datatype.  The > on;y way I know of to fix this is to... > > 1) add a new column as timestamptz called 'tmp' (whatever) > 2) update tmp with the value in the timestamp collumn perhaps using "at > time zone 'utc' " > 3) drop the original timestamp column > 4) recreate the column with the same name but with data type timestamptz > 5) Move all the records over to this column (from tmp) > 6) drop the tmp column. > > There would be some needed downtime to do this of course. > > Is there an easier way? create table ts_test(id int, ts_fld timestamp); insert into ts_test values (1, now()), (2, now() - interval '1 day'); test_(aklaver)> select * from ts_test ; id | ts_fld ----+---------------------------- 1 | 2018-07-11 14:24:43.960989 2 | 2018-07-10 14:24:43.960989 (2 rows) Assuming the timestamp values where at UTC: alter table ts_test alter COLUMN ts_fld type timestamptz using ts_fld at time zone 'UTC'; test_(aklaver)> select * from ts_test ; id | ts_fld ----+------------------------------- 1 | 2018-07-11 07:28:17.279899-07 2 | 2018-07-10 07:28:17.279899-07 The above depends on you knowing what the timestamps in the timestamp field where entered as. I would test first. See below for more info: https://www.postgresql.org/docs/10/static/sql-altertable.html > > On Wed, Jul 11, 2018 at 5:14 PM, Adrian Klaver > > wrote: > > On 07/11/2018 01:34 PM, David Gauthier wrote: > > Thanks Everyone, they all work, but TL's seems to be the simplest... > select current_timestamp(0) at time zone 'utc' > > I'm kinda stuck with the timestamp data type (vs timestamptz). > Wondering if I can stick with that. > > > The above is at little unclear. Can you change the data type or not? > If you can your life will be a lot easier if you change it to > timestamptz. > > > One last question... > I want to store the current UTC date/time in the DB.  Does PG > unconditionally store something like UTC, then let the queries > figure out how they want to look at it (with "at time zone" and > "to_char()" etc...) ?  Or do I have to intentionally store the > UTC value somehow? > > > Per: > > https://www.postgresql.org/docs/10/static/datatype-datetime.html > > > "For timestamp with time zone, the internally stored value is always > in UTC (Universal Coordinated Time, traditionally known as Greenwich > Mean Time, GMT). An input value that has an explicit time zone > specified is converted to UTC using the appropriate offset for that > time zone. If no time zone is stated in the input string, then it is > assumed to be in the time zone indicated by the system's TimeZone > parameter, and is converted to UTC using the offset for the timezone > zone. > > When a timestamp with time zone value is output, it is always > converted from UTC to the current timezone zone, and displayed as > local time in that zone. To see the time in another time zone, > either change timezone or use the AT TIME ZONE construct (see > Section 9.9.3). > > Conversions between timestamp without time zone and timestamp with > time zone normally assume that the timestamp without time zone value > should be taken or given as timezone local time. A different time > zone can be specified for the conversion using AT TIME ZONE." > > > Right now the code is just inserting and updating records using > "localtimestamp(0)". > > > > > On Wed, Jul 11, 2018 at 4:11 PM, David G. Johnston > > >> wrote: > >     On Wednesday, July 11, 2018, David Gauthier >     > >> wrote: > >         OK, the "to_char" gets rid of the timezone extension. > But the >         times still don't make sense. > >         When I go to store this in a DB, I want to store the > UTC time.         How d I do that ? > >     Use the data type that represents exactly that, > timestamptz.  Using >     the timestamp data type is generally not what you want even > if you >     can get the manipulation logic figured out. > >     David J. > > > > > -- > Adrian Klaver > adrian.klaver@aklaver.com > > -- Adrian Klaver adrian.klaver@aklaver.com