Thread: Bug in AdjustIntervalForTypmod function

Bug in AdjustIntervalForTypmod function

From
"Donald Fraser"
Date:
PostgreSQL 7.3.2 on i686-pc-linux-gnu, compiled by GCC 2.96

The following function definition:

extern Datum testDate(PG_FUNCTION_ARGS);
PG_FUNCTION_INFO_V1(testDate);

Datum
testDate(PG_FUNCTION_ARGS)
{
 Datum tnow =3D DirectFunctionCall3(timestamp_in,
    CStringGetDatum("now"),
    ObjectIdGetDatum(InvalidOid),
    Int32GetDatum(0));
=20=20=20=20
 Datum interv =3D DirectFunctionCall3(interval_in,
    CStringGetDatum("7 Days"),
    ObjectIdGetDatum(InvalidOid),
    Int32GetDatum(0));
=20=20=20=20
 Datum tnow_pl_interval =3D DirectFunctionCall2(timestamp_pl_span,
    tnow,
    interv);
=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20
 text *ptext =3D DatumGetTextP(DirectFunctionCall1(textin, DirectFunctionCa=
ll1(timestamp_out,tnow_pl_interval)));

 if (ptext =3D=3D NULL)
     PG_RETURN_NULL();
 PG_RETURN_TEXT_P(ptext);
}

When called such as:
Bugs=3D> SELECT "testDate"();

Produces this error message:
ERROR:  AdjustIntervalForTypmod(): internal coding error

Yet when I call the equivalent SQL it reports no error, such as:
Bugs=3D> SELECT timestamp_pl_span('now'::timestamp(0), '7 Days'::interval(0=
));
  timestamp_pl_span
---------------------
 2003-05-20 17:35:21
(1 row)

I searched through the code and found that the failure was occuring in the =
function:=20
"static void AdjustIntervalForTypmod(Interval *interval, int32 typmod)"

To get around the problem I set the type modifier for the "Interval" as "-1=
".

Regards
Donald Fraser

Re: Bug in AdjustIntervalForTypmod function

From
Tom Lane
Date:
"Donald Fraser" <demolish@cwgsy.net> writes:
> ERROR:  AdjustIntervalForTypmod(): internal coding error

You passed it a typmod that's illegal for INTERVAL, viz 0.

-1 is the correct default typmod if you don't know the conventions
for a particular type's typmod values.

            regards, tom lane

Re: Bug in AdjustIntervalForTypmod function

From
"Donald Fraser"
Date:
----- Original Message -----
From: "Tom Lane" <tgl@sss.pgh.pa.us>
To: "Donald Fraser" <demolish@cwgsy.net>
Cc: "[BUGS]" <pgsql-bugs@postgresql.org>
Sent: Tuesday, May 13, 2003 6:44 PM
Subject: Re: [BUGS] Bug in AdjustIntervalForTypmod function


> "Donald Fraser" <demolish@cwgsy.net> writes:
> > ERROR:  AdjustIntervalForTypmod(): internal coding error
>
> You passed it a typmod that's illegal for INTERVAL, viz 0.

Having executed thus:
Bugs=>SELECT '7 Days'::interval(7);
ERROR:  INTERVAL(7) precision must be between 0 and 6

I assumed that the typmod for the interval_in function was in the above range.
Sorry about that.

Thanks
Donald.