Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 24AE4633A35 for ; Mon, 29 Jun 2009 11:25:36 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 84421-07 for ; Mon, 29 Jun 2009 11:25:34 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id EB48A632529 for ; Mon, 29 Jun 2009 11:25:34 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id n5TEPLib011725; Mon, 29 Jun 2009 10:25:21 -0400 (EDT) To: Mario Splivalo cc: pgsql Subject: Re: date_trunc should be called date_round? In-reply-to: <4A487F94.3070303@megafon.hr> References: <4A487F94.3070303@megafon.hr> Comments: In-reply-to Mario Splivalo message dated "Mon, 29 Jun 2009 10:47:16 +0200" Date: Mon, 29 Jun 2009 10:25:20 -0400 Message-ID: <11724.1246285520@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200906/122 X-Sequence-Number: 32727 Mario Splivalo writes: > But, date_trunc behaves like round function: round(1.9) = 2. Hmm ... only for float timestamps, and only for the millisec/microsec cases. case DTK_MILLISEC: #ifdef HAVE_INT64_TIMESTAMP fsec = (fsec / 1000) * 1000; #else fsec = rint(fsec * 1000) / 1000; #endif break; case DTK_MICROSEC: #ifndef HAVE_INT64_TIMESTAMP fsec = rint(fsec * 1000000) / 1000000; #endif break; I wonder if we should change this to use floor() instead. regards, tom lane