Обсуждение: Interval bug

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

Interval bug

От
Laurette Cisneros
Дата:
Howdy hackers,

Should I file a bug or is this known (or fixed)?

Thanks!

Laurette (laurette@nextbus.com)

Here's the psql ready test and description:

--
-- BUG Description:
-- A float with zeros on the right of the decimal
-- fails conversion to an interval.
-- interval ( int ) works
-- interval ( float ) works
-- interval ( float where 0 on the right of decimal ) fail.
--
-- The first set of selects labelled "No Casting" show this
-- problem.
--
-- To further diagnose the problem, I tried each query
-- with a cast to integer, float and float8.
-- This diagnosis is shown in the section labelled "With Casting".
-- Note that the float value cast to integer fails due to
-- strtol called by pg_atoi(). (Stupid strtol).
-- 
-- Possible solution:
-- In postgresql-7.1.3:src/backend/utils/datetime.c,
-- function ParseDateTime line 442:
-- 
-- This if statement forces a string containing a decimal
-- to be typed as a date.  Although dates can contain decimal
-- delimiters, it is more common for decimal delimiters to be
-- assumed to be floats.  Perhaps the algorithm could change
-- so that 2 decimals in the string makes it a date and only
-- one makes it a float and therefore time.  The alternative
-- is to force strings with decimals into floats only and therefore
-- numeric and time only.
--
\echo ===========================================
\echo No casting
\echo ===========================================
\echo select interval(301);  expect 00:05:01
select interval( 301 );
\echo
\echo select interval( 301.01 ); expect 00:05:01.01
select interval( 301.01 );
\echo
\echo select interval( 301.00 ); expect 00:05:01 get error on interval
select interval( 301.00 );

\echo ===========================================
\echo With casting
\echo ===========================================
\echo
\echo select interval( 301::integer); expect 00:05:01
select interval( 301::integer );
\echo select interval( 301::float); expect 00:05:01
select interval( 301::float );
\echo select interval( 301::float8 ); expect 00:05:01
select interval( 301::float8 );
\echo
\echo select interval( 301.01::integer); expect 00:05:01.01; pg_atoi message caused by strtol
select interval( 301.01::integer );
\echo select interval( 301.01::float); expect 00:05:01.01
select interval( 301.01::float );
\echo select interval( 301.01::float8); expect 00:05:01.01
select interval( 301.01::float8 );
\echo
\echo select interval( 301.00::integer); expect 00:05:01; pg_atoi message caused by strtol
select interval( 301.00::integer );
\echo select interval( 301.00::float); expect 00:05:01
select interval( 301.00::float );
\echo select interval( 301.00::float8); expect 00:05:01
select interval( 301.00::float8);





Re: Interval bug

От
Tom Lane
Дата:
Laurette Cisneros <laurette@nextbus.com> writes:
> Should I file a bug or is this known (or fixed)?

The problem appears to be gone in current development sources:

regression=#  select interval( 301.00 );interval
----------00:05:01
(1 row)

The particular code you mentioned seems unchanged, so the fix was
evidently elsewhere.
        regards, tom lane