Re: text -> time cast problem

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Brent Verner <brent(at)rcfile(dot)org>, PostgreSQL Development <pgsql-hackers(at)postgresql(dot)org>, Thomas Lockhart <lockhart(at)fourpalms(dot)org>
Subject: Re: text -> time cast problem
Date: 2001-12-04 22:00:54
Message-ID: Pine.LNX.4.30.0112042231210.618-100000@peter.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Tom Lane writes:

> Brent Verner <brent(at)rcfile(dot)org> writes:
> > I noticed an incorrect example in doc/src/sgml/func.sgml...
> > brent=# SELECT EXTRACT(SECOND FROM TIME '17:12:28.5');
> > date_part
> > -----------
> > 28
> > (1 row)
>
> > The documentation says this should return 28.5.
>
> Historically we've made EXTRACT(SECOND) return integral seconds, with
> MILLISECOND/MICROSECOND field names for the fractional seconds. So the
> docs are incorrect with respect to the actual code behavior.

Nope, the docs represent the behavior of the code at the time the docs
were written. The code is now in error with respect to the documented
behaviour. A quick check shows that PostgreSQL 7.0.2 agrees with
including the fractional part. Probably this was broken as part of the
time/timestamp precision changes. Definitely looks like a show-stopper to
me.

> BTW, this means that
>
> SELECT EXTRACT(SECOND FROM TIME '17:12:28.5');
>
> *should* return 28, because the TIME literal is implicitly TIME(0).
> But if it were written TIME(1) '17:12:28.5' or more precision, then

That appears to be what it does, but it's not correct. I point you to
SQL92:

16)The data type of a <time literal> that does not specify <time
zone interval> is TIME(P), where P is the number of digits in
<seconds fraction>, if specified, and 0 otherwise. The data
type of a <time literal> that specifies <time zone interval>
is TIME(P) WITH TIME ZONE, where P is the number of digits in
<seconds fraction>, if specified, and 0 otherwise.

In this "time literal" context, TIME does not take a precision value at
all. The new code certainly has this wrong.

For details, I refer you to my Oct 5 message "Unhappiness with forced
precision conversion for timestamp", where we already discussed
essentially the same issue, but apparently we never did anything about it.

--
Peter Eisentraut peter_e(at)gmx(dot)net

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jan Wieck 2001-12-04 22:19:00 Re: RC1 on Monday?
Previous Message Bruce Momjian 2001-12-04 21:43:20 Re: [ADMIN] compression -Fx "problem"