Re: date_trunc should be called date_round?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Mario Splivalo <mario(dot)splivalo(at)megafon(dot)hr>
Cc: pgsql <pgsql-sql(at)postgresql(dot)org>
Subject: Re: date_trunc should be called date_round?
Date: 2009-06-29 14:25:20
Message-ID: 11724.1246285520@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Mario Splivalo <mario(dot)splivalo(at)megafon(dot)hr> 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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Robert Edwards 2009-06-30 00:22:12 Re: uniqueness constraint with NULLs
Previous Message Tom Lane 2009-06-29 14:01:23 Re: uniqueness constraint with NULLs