Interval bug

From: Laurette Cisneros <laurette(at)nextbus(dot)com>
To: <pgsql-hackers(at)postgresql(dot)org>
Subject: Interval bug
Date: 2001-10-05 16:15:09
Message-ID: Pine.LNX.4.33.0110050914420.24322-100000@visor.corp.nextbus.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Howdy hackers,

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

Thanks!

Laurette (laurette(at)nextbus(dot)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);

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2001-10-05 17:42:01 Re: Problem on AIX with current
Previous Message Bruce Momjian 2001-10-05 15:48:16 Re: Problem on AIX with current