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 1g0t2X-0001Tk-Ff for pgsql-general@arkaria.postgresql.org; Fri, 14 Sep 2018 18:42:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g0t2U-0004ka-RU for pgsql-general@arkaria.postgresql.org; Fri, 14 Sep 2018 18:41:58 +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 1g0t2U-0004kS-G2 for pgsql-general@lists.postgresql.org; Fri, 14 Sep 2018 18:41:58 +0000 Received: from mta1.recol.net ([64.207.103.6]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g0t2R-0001SY-5N for pgsql-general@lists.postgresql.org; Fri, 14 Sep 2018 18:41:56 +0000 Received: from steamer.attlocal.net (162-194-37-157.lightspeed.brhmal.sbcglobal.net [162.194.37.157]) by mta1.recol.net (Postfix) with ESMTPSA id 39177398A83; Fri, 14 Sep 2018 14:41:53 -0400 (EDT) Date: Fri, 14 Sep 2018 13:40:22 -0500 From: Steven Lembark To: pgsql-general@lists.postgresql.org Cc: lembark@wrkhors.com, David Gauthier Subject: Re: Convert interval to hours Message-ID: <20180914134014.18a9cf7d@wrkhors.com> In-Reply-To: References: <20180914111050.16b7af88@steamer.attlocal.net> Organization: Workhorse Computing X-Mailer: Claws Mail 3.17.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Fri, 14 Sep 2018 12:21:14 -0400 David Gauthier wrote: > I'm using postgres v9.5.2 on RH6. PG can convert the times for you. For times (not timestamps) you are always better off dealing with either time or integer seconds. There are a variety of issues with rouding that affect repeatability and accuracy of results using floats or doubles. Given that 10 and three are both continuing fractions in binary (e.g., 1/10 binary is an infinite series) division by 3600 will only cause you annoyance at some point. If you are subtracting times then you will (usually) end up with an interval, which can be cast to seconds in the query and give you precise, accurate, repeatable results every time. e.g., select extract ( epoch from ( time1 - time2 )::interval ) as "seconds", ... is one approach. In nearly all cases you are better off selecting and converting the time in SQL rather than converting the start and end times from numeric (time) to string (DBI) and then back from char * to float/double or int/unsigned. The charaacter conversion is expensive and numeric -> string -> numeric leaes you open to all sorts of rouding and conversion issues. Frankly, if you have to run the query more than once I'd suggest adding a view that does the select/convert for you (along with dealing with any NULL's that creep into things). PG makes it quite easy to add the view and quite in-expensive to apply it. -- Steven Lembark 3920 10th Ave South Workhorse Computing Birmingham, AL 35222 lembark@wrkhors.com +1 888 359 3508 -- Steven Lembark 3920 10th Ave South Workhorse Computing Birmingham, AL 35222 lembark@wrkhors.com +1 888 359 3508