Make pg_get_statisticsobjdef_expressions return NULL
authorTomas Vondra <tomas.vondra@postgresql.org>
Fri, 7 May 2021 11:56:32 +0000 (13:56 +0200)
committerTomas Vondra <tomas.vondra@postgresql.org>
Fri, 7 May 2021 12:34:16 +0000 (14:34 +0200)
The usual behavior for functions in ruleutils.c is to return NULL when
the object does not exist. pg_get_statisticsobjdef_expressions raised an
error instead, so correct that.

Reported-by: Justin Pryzby
Discussion: https://postgr.es/m/20210505210947.GA27406%40telsasoft.com

src/backend/utils/adt/ruleutils.c

index 0a4fa93d0160810c823dab2e9e5af5b995085c45..881e8ec03d29655dfc0ff20de052255c46257470 100644 (file)
@@ -1759,9 +1759,9 @@ pg_get_statisticsobjdef_expressions(PG_FUNCTION_ARGS)
        statexttup = SearchSysCache1(STATEXTOID, ObjectIdGetDatum(statextid));
 
        if (!HeapTupleIsValid(statexttup))
-               elog(ERROR, "cache lookup failed for statistics object %u", statextid);
+               PG_RETURN_NULL();
 
-       /* has the statistics expressions? */
+       /* Does the stats object have expressions? */
        has_exprs = !heap_attisnull(statexttup, Anum_pg_statistic_ext_stxexprs, NULL);
 
        /* no expressions? we're done */