text -> time cast problem

Поиск
Список
Период
Сортировка
Искать

text -> time cast problem

От:
Brent Verner <brent@rcfile.org>
Дата:
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.  Digging a bit, I
noticed the following (discrepancy?).  Is this desired behavior?

brent=# select "time"('12:00:12.5');   time     
-------------12:00:12.50
(1 row)

brent=# select '12:00:12.5'::time;  time   
----------12:00:12
(1 row)

IMO, one of these needs to be fixed before RC1 is rolled.


On a similar note, it would be neat if there was an sgml tag like  SELECT EXTRACT(SECOND FROM TIME '17:12:28.5'); 
that would dynamically execute the query and insert the result in
the sgml file...  This would ensure the docs always agree with current
behavior ;-)

cheers. brent

-- 
"Develop your talent, man, and leave the world something. Records are 
really gifts from people. To think that an artist would love you enough
to share his music with anyone is a beautiful thing."  -- Duane Allman

Re: text -> time cast problem

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Brent Verner  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.

But ...

The SQL92 spec appears to intend that EXTRACT(SECOND) should return
seconds *and* fractional seconds.  In 6.6 syntax rule 4,
        4) If  is specified, then
           Case:
           a) If  does not specify SECOND, then the data             type of the result is exact numeric with implementation-             defined precision and scale 0.
           b) Otherwise, the data type of the result is exact numeric             with implementation-defined precision and scale. The             implementation-defined scale shall not be less than the spec-             ified or implied 

Re: text -> time cast problem

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Peter Eisentraut  writes:
> 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.

[ checks ... ] As does 7.1.  You're right, that is how it used to behave.

> 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.

I think the rest of us were waiting on Lockhart to opine about it ...
not to mention do something about it ...
		regards, tom lane

Re: text -> time cast problem

От:
Peter Eisentraut <peter_e@gmx.net>
Дата:
Tom Lane writes:

> Brent Verner  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 

Re: text -> time cast problem

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Peter Eisentraut  writes:
> That appears to be what it does, but it's not correct.  I point you to
> SQL92:

>          16)The data type of a 

Re: text -> time cast problem

От:
Brent Verner <brent@rcfile.org>
Дата:
[2001-12-04 18:15] Tom Lane said:
| Peter Eisentraut  writes:
| > That appears to be what it does, but it's not correct.  I point you to
| > SQL92:
| 
| >          16)The data type of a 

Re: text -> time cast problem

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Brent Verner  writes:
> [2001-12-04 18:15] Tom Lane said:
> | But you are definitely right that
> | 
> | 		time '17:12:28.123'

> sql-99 seems to contradict this assertion.
> page 160 (Syntax Rules, 6.1 ) 
>   30) If 

Re: text -> time cast problem

От:
Brent Verner <brent@rcfile.org>
Дата:
[2001-12-06 13:00] Tom Lane said:
| Brent Verner  writes:
| > [2001-12-04 18:15] Tom Lane said:
| > | But you are definitely right that
| > | 
| > | 		time '17:12:28.123'
| 
| > sql-99 seems to contradict this assertion.
| > page 160 (Syntax Rules, 6.1 )
|   
| >   30) If 

Re: text -> time cast problem

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Brent Verner  writes:
> This seems fair.  Would this approach imply that CURRENT_TIME and 
> CURRENT_TIMESTAMP should not apply default precision to their return 
> values?  Right now, "CURRENT_TIME" is equivalent to "CURRENT_TIME(0)" 
> and "CURRENT_TIMESTAMP" eq to "CURRENT_TIMESTAMP(6)".

Yes, I had been thinking that myself, but hadn't got round to mentioning
it to the list yet.  (Even if you do accept default precisions for time
& timestamp columns, I can see nothing in the spec that justifies
applying those default precisions to CURRENT_TIME/TIMESTAMP.  AFAICS,
the precision of their results when they are given no argument is
just plain not specified.)
		regards, tom lane

Re: text -> time cast problem

От:
Thomas Lockhart <lockhart@fourpalms.org>
Дата:
> > This seems fair.  Would this approach imply that CURRENT_TIME and
> > CURRENT_TIMESTAMP should not apply default precision to their return
> > values?  Right now, "CURRENT_TIME" is equivalent to "CURRENT_TIME(0)"
> > and "CURRENT_TIMESTAMP" eq to "CURRENT_TIMESTAMP(6)".
> Yes, I had been thinking that myself, but hadn't got round to mentioning
> it to the list yet.  (Even if you do accept default precisions for time
> & timestamp columns, I can see nothing in the spec that justifies
> applying those default precisions to CURRENT_TIME/TIMESTAMP.  AFAICS,
> the precision of their results when they are given no argument is
> just plain not specified.)

I'll shift the default precisions of CURRENT_TIME to match that of
CURRENT_TIMESTAMP, which is currently six (6). As you might know, 7.2
has sub-second system time available, which was not true in previous
releases. But that time is only good to microseconds, so the six digits
of precision is a good match for that.
                     - Thomas

Re: text -> time cast problem

От:
"Christopher Kings-Lynne" <chriskl@familyhealth.com.au>
Дата:
Just a quick question for 7.1.3:

I notice that where as you can do this:

insert into table values ('now');

To insert a current timestamp, if you try using the more standard syntax:

insert into table values ('CURRENT_TIMESTAMP');

You get the word 'current' inserted.  However if you do this:

insert into table values (CURRENT_TIMESTAMP);

It works as expected.

Is there anything wrong with any of these behaviours, and has any of it been
changed for 7.2?  I kind think that the quoted CURRENT_TIMESTAMP should work
just like the unquoted...

Chris

> -----Original Message-----
> From: pgsql-hackers-owner@postgresql.org
> [mailto:pgsql-hackers-owner@postgresql.org]On Behalf Of Tom Lane
> Sent: Friday, 7 December 2001 10:21 PM
> To: Brent Verner
> Cc: Peter Eisentraut; PostgreSQL Development; Thomas Lockhart
> Subject: Re: [HACKERS] text -> time cast problem
>
>
> Brent Verner  writes:
> > This seems fair.  Would this approach imply that CURRENT_TIME and
> > CURRENT_TIMESTAMP should not apply default precision to their return
> > values?  Right now, "CURRENT_TIME" is equivalent to "CURRENT_TIME(0)"
> > and "CURRENT_TIMESTAMP" eq to "CURRENT_TIMESTAMP(6)".
>
> Yes, I had been thinking that myself, but hadn't got round to mentioning
> it to the list yet.  (Even if you do accept default precisions for time
> & timestamp columns, I can see nothing in the spec that justifies
> applying those default precisions to CURRENT_TIME/TIMESTAMP.  AFAICS,
> the precision of their results when they are given no argument is
> just plain not specified.)
>
> 			regards, tom lane
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>     (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
>


Re: text -> time cast problem

От:
Thomas Lockhart <lockhart@fourpalms.org>
Дата:
...
> Is there anything wrong with any of these behaviours, and has any of it been
> changed for 7.2?  I kind think that the quoted CURRENT_TIMESTAMP should work
> just like the unquoted...

No, it is pretty much the same as before. Quoted 'current_timestamp' has
nothing to do with the SQL9x standard, while unquoted CURRENT_TIMESTAMP
does. For 7.2, we are dropping the somewhat interesting 'current' value,
which was evaluated at the time a math operation was performed, at which
time it became equivalent to 'now'.
                  - Thomas

Re: text -> time cast problem

От:
Bruce Momjian <pgman@candle.pha.pa.us>
Дата:
> > > This seems fair.  Would this approach imply that CURRENT_TIME and
> > > CURRENT_TIMESTAMP should not apply default precision to their return
> > > values?  Right now, "CURRENT_TIME" is equivalent to "CURRENT_TIME(0)"
> > > and "CURRENT_TIMESTAMP" eq to "CURRENT_TIMESTAMP(6)".
> > Yes, I had been thinking that myself, but hadn't got round to mentioning
> > it to the list yet.  (Even if you do accept default precisions for time
> > & timestamp columns, I can see nothing in the spec that justifies
> > applying those default precisions to CURRENT_TIME/TIMESTAMP.  AFAICS,
> > the precision of their results when they are given no argument is
> > just plain not specified.)
> 
> I'll shift the default precisions of CURRENT_TIME to match that of
> CURRENT_TIMESTAMP, which is currently six (6). As you might know, 7.2
> has sub-second system time available, which was not true in previous
> releases. But that time is only good to microseconds, so the six digits
> of precision is a good match for that.

Is this all resolved?

--  Bruce Momjian                        |  http://candle.pha.pa.us pgman@candle.pha.pa.us               |  (610) 853-3000 +  If your life is a hard drive,     |  830 Blythe Avenue +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026

Re: text -> time cast problem

От:
Thomas Lockhart <lockhart@fourpalms.org>
Дата:
...
> Is this all resolved?

Some time ago, yes. (Pun intended ;)
                - Thomas

Re: text -> time cast problem

От:
Bruce Momjian <pgman@candle.pha.pa.us>
Дата:
> ...
> > Is this all resolved?
> 
> Some time ago, yes. (Pun intended ;)

Thanks.  Sometimes I can not tell from the email messages.

--  Bruce Momjian                        |  http://candle.pha.pa.us pgman@candle.pha.pa.us               |  (610) 853-3000 +  If your life is a hard drive,     |  830 Blythe Avenue +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026

FAQ