Re: date_part()/EXTRACT(second) behaviour with time data type

Lists: pgsql-hackers
From: Gregory Stark <stark(at)mit(dot)edu>
To: Postgres <pgsql-hackers(at)postgresql(dot)org>
Subject: date_part()/EXTRACT(second) behaviour with time data type
Date: 2009-07-29 15:15:30
Message-ID: 87ocr31pwt.fsf@oxford.xeocode.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


I think we broke date_part for extracting seconds from time arguments. It
appears we leave out the milliseconds whereas we don't for timestamp
arguments. This was not the case in 8.3 where we included the milliseconds for
both data types.

Unless this is intentional? I know we wacked around both the meaning of SECOND
for intervals and the code for date_part in a lot of ways. But I don't see why
it would be different for time versus timestamp.

postgres=# select extract(second from now()::time with time zone);
date_part
-----------
27
(1 row)

postgres=# select extract(second from now()::time without time zone);
date_part
-----------
27
(1 row)

postgres=# select extract(second from now()::timestamp with time zone);
date_part
-----------
27.782458
(1 row)

postgres=# select extract(second from now()::timestamp without time zone);
date_part
-----------
27.782458
(1 row)

--
Gregory Stark
http://mit.edu/~gsstark/resume.pdf


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Gregory Stark <stark(at)mit(dot)edu>
Cc: Postgres <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: date_part()/EXTRACT(second) behaviour with time data type
Date: 2009-07-29 16:15:42
Message-ID: 19958.1248884142@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Gregory Stark <stark(at)mit(dot)edu> writes:
> I think we broke date_part for extracting seconds from time arguments. It
> appears we leave out the milliseconds whereas we don't for timestamp
> arguments. This was not the case in 8.3 where we included the milliseconds for
> both data types.

It's not new. This appears to be a difference between the integer and
float timestamp code paths, and I'd say it's probably a thinko:

case DTK_SECOND:
#ifdef HAVE_INT64_TIMESTAMP
result = tm->tm_sec + fsec / USECS_PER_SEC;
#else
result = tm->tm_sec + fsec;
#endif
break;

In the integer case, fsec is an integer and so the division loses the
fraction. timestamptz_part does this instead:

case DTK_SECOND:
#ifdef HAVE_INT64_TIMESTAMP
result = tm->tm_sec + fsec / 1000000.0;
#else
result = tm->tm_sec + fsec;
#endif
break;

I agree that we should change it, but should we back-patch it, and if so
how far?

regards, tom lane


From: Greg Stark <stark(at)mit(dot)edu>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Postgres <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: date_part()/EXTRACT(second) behaviour with time data type
Date: 2009-07-29 17:07:16
Message-ID: 407d949e0907291007p6817d4e1u91b964fe7a16ec2a@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, Jul 29, 2009 at 5:15 PM, Tom Lane<tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> I agree that we should change it, but should we back-patch it, and if so
> how far?
>

Well at least to 8.4 so someone who has just always been using
downloaded binaries or binaries compiled with the default
configuration continues to get the same behaviour.

My inclination would be to backpatch it further back. But I'm not 100%
sure either.

--
greg
http://mit.edu/~gsstark/resume.pdf


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Greg Stark <stark(at)mit(dot)edu>
Cc: Postgres <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: date_part()/EXTRACT(second) behaviour with time data type
Date: 2009-07-29 19:00:58
Message-ID: 28560.1248894058@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Greg Stark <stark(at)mit(dot)edu> writes:
> On Wed, Jul 29, 2009 at 5:15 PM, Tom Lane<tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>> I agree that we should change it, but should we back-patch it, and if so
>> how far?

> Well at least to 8.4 so someone who has just always been using
> downloaded binaries or binaries compiled with the default
> configuration continues to get the same behaviour.

> My inclination would be to backpatch it further back. But I'm not 100%
> sure either.

Given the lack of prior complaints, I'm thinking just to 8.4 is a good
compromise. Any objections out there?

regards, tom lane