Skip to content

Commit a873de4

Browse files
jianhe-funCommitfest Bot
authored andcommitted
error safe for casting interval to other types per pg_cast
select castsource::regtype, casttarget::regtype, castfunc, castcontext,castmethod, pp.prosrc, pp.proname from pg_cast pc join pg_proc pp on pp.oid = pc.castfunc and pc.castfunc > 0 and castsource::regtype = 'interval'::regtype order by castsource::regtype; castsource | casttarget | castfunc | castcontext | castmethod | prosrc | proname ------------+------------------------+----------+-------------+------------+----------------+---------- interval | time without time zone | 1419 | a | f | interval_time | time interval | interval | 1200 | i | f | interval_scale | interval (2 rows) discussion: https://postgr.es/m/CADkLM=fv1JfY4Ufa-jcwwNbjQixNViskQ8jZu3Tz_p656i_4hQ@mail.gmail.com
1 parent 60b490d commit a873de4

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/backend/utils/adt/date.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2106,7 +2106,7 @@ interval_time(PG_FUNCTION_ARGS)
21062106
TimeADT result;
21072107

21082108
if (INTERVAL_NOT_FINITE(span))
2109-
ereport(ERROR,
2109+
ereturn(fcinfo->context, (Datum) 0,
21102110
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
21112111
errmsg("cannot convert infinite interval to time")));
21122112

src/backend/utils/adt/timestamp.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1334,7 +1334,8 @@ interval_scale(PG_FUNCTION_ARGS)
13341334
result = palloc(sizeof(Interval));
13351335
*result = *interval;
13361336

1337-
AdjustIntervalForTypmod(result, typmod, NULL);
1337+
if (!AdjustIntervalForTypmod(result, typmod, fcinfo->context))
1338+
PG_RETURN_NULL();
13381339

13391340
PG_RETURN_INTERVAL_P(result);
13401341
}

0 commit comments

Comments
 (0)