1
0
mirror of https://github.com/postgres/postgres.git synced 2025-10-21 02:52:47 +03:00

Use ereport rather than elog in WinCheckAndInitializeNullTreatment.

Previously WinCheckAndInitializeNullTreatment() used elog() to emit an
error message. ereport() should be used instead because it's a
user-facing error. Also use existing get_func_name() to get a
function's name, rather than own implementation.

Moreover add an assertion to validate winobj parameter, just like
other window function API.

Reported-by: Tom Lane <tgl@sss.pgh.pa.us>
Author: Tatsuo Ishii <ishii@postgresql.org>
Reviewed-by: Chao Li <lic@highgo.com>
Discussion: https://postgr.es/m/2952409.1760023154%40sss.pgh.pa.us
This commit is contained in:
Tatsuo Ishii
2025-10-14 19:15:24 +09:00
parent 1206df04c2
commit 5f3808646f

View File

@@ -3538,24 +3538,20 @@ WinCheckAndInitializeNullTreatment(WindowObject winobj,
bool allowNullTreatment, bool allowNullTreatment,
FunctionCallInfo fcinfo) FunctionCallInfo fcinfo)
{ {
Assert(WindowObjectIsValid(winobj));
if (winobj->ignore_nulls != NO_NULLTREATMENT && !allowNullTreatment) if (winobj->ignore_nulls != NO_NULLTREATMENT && !allowNullTreatment)
{ {
HeapTuple proctup; const char *funcname = get_func_name(fcinfo->flinfo->fn_oid);
Form_pg_proc procform;
Oid funcid;
funcid = fcinfo->flinfo->fn_oid; if (!funcname)
proctup = SearchSysCache1(PROCOID, elog(ERROR, "could not get function name");
ObjectIdGetDatum(funcid)); ereport(ERROR,
if (!HeapTupleIsValid(proctup)) (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
elog(ERROR, "cache lookup failed for function %u", funcid); errmsg("function %s does not allow RESPECT/IGNORE NULLS",
procform = (Form_pg_proc) GETSTRUCT(proctup); funcname)));
elog(ERROR, "function %s does not allow RESPECT/IGNORE NULLS",
NameStr(procform->proname));
} }
else if (winobj->ignore_nulls == PARSER_IGNORE_NULLS) else if (winobj->ignore_nulls == PARSER_IGNORE_NULLS)
winobj->ignore_nulls = IGNORE_NULLS; winobj->ignore_nulls = IGNORE_NULLS;
} }
/* /*