Bug in AdjustIntervalForTypmod function
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 = DirectFunctionCall3(timestamp_in,
CStringGetDatum("now"),
ObjectIdGetDatum(InvalidOid),
Int32GetDatum(0));
Datum interv = DirectFunctionCall3(interval_in,
CStringGetDatum("7 Days"),
ObjectIdGetDatum(InvalidOid),
Int32GetDatum(0));
Datum tnow_pl_interval = DirectFunctionCall2(timestamp_pl_span,
tnow,
interv);
text *ptext = DatumGetTextP(DirectFunctionCall1(textin, DirectFunctionCall1(timestamp_out,tnow_pl_interval)));
if (ptext == NULL)
PG_RETURN_NULL();
PG_RETURN_TEXT_P(ptext);
}
When called such as:
Bugs=> 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=> 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:
"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
"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
----- 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.