Provide more-specific error details/hints for function lookup failures.
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 16 Sep 2025 16:17:02 +0000 (12:17 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 16 Sep 2025 16:17:02 +0000 (12:17 -0400)
commit83a56419457ec0eff2eddfed8eb3aba86bede9cc
treec93d0986e7d19c763c2d0965d98edc8d336b78ea
parentc7b0cb367d3c6b007122457ad5deb659fe8cc266
Provide more-specific error details/hints for function lookup failures.

Up to now we've contented ourselves with a one-size-fits-all error
hint when we fail to find any match to a function or procedure call.
That was mostly okay in the beginning, but it was never great, and
since the introduction of named arguments it's really not adequate.
We at least ought to distinguish "function name doesn't exist" from
"function name exists, but not with those argument names".  And the
rules for named-argument matching are arcane enough that some more
detail seems warranted if we match the argument names but the call
still doesn't work.

This patch creates a framework for dealing with these problems:
FuncnameGetCandidates and related code will now pass back a bitmask of
flags showing how far the match succeeded.  This allows a considerable
amount of granularity in the reports.  The set-bits-in-a-bitmask
approach means that when there are multiple candidate functions, the
report will reflect the match(es) that got the furthest, which seems
correct.  Also, we can avoid mentioning "maybe add casts" unless
failure to match argument types is actually the issue.

Extend the same return-a-bitmask approach to OpernameGetCandidates.
The issues around argument names don't apply to operator syntax,
but it still seems worth distinguishing between "there is no
operator of that name" and "we couldn't match the argument types".

While at it, adjust these messages and related ones to more strictly
separate "detail" from "hint", following our message style guidelines'
distinction between those.

Reported-by: Dominique Devienne <ddevienne@gmail.com>
Author: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Robert Haas <robertmhaas@gmail.com>
Discussion: https://postgr.es/m/1756041.1754616558@sss.pgh.pa.us
44 files changed:
contrib/postgres_fdw/expected/postgres_fdw.out
doc/src/sgml/sources.sgml
doc/src/sgml/typeconv.sgml
src/backend/catalog/namespace.c
src/backend/catalog/pg_aggregate.c
src/backend/parser/parse_func.c
src/backend/parser/parse_oper.c
src/backend/utils/adt/regproc.c
src/backend/utils/adt/ruleutils.c
src/include/catalog/namespace.h
src/include/parser/parse_func.h
src/pl/plperl/expected/plperl_elog.out
src/pl/plperl/expected/plperl_elog_1.out
src/pl/plpgsql/src/expected/plpgsql_call.out
src/pl/plpgsql/src/expected/plpgsql_record.out
src/pl/plpython/expected/plpython_error.out
src/test/modules/libpq_pipeline/traces/pipeline_abort.trace
src/test/modules/test_extensions/expected/test_extensions.out
src/test/regress/expected/alter_table.out
src/test/regress/expected/arrays.out
src/test/regress/expected/create_cast.out
src/test/regress/expected/create_function_sql.out
src/test/regress/expected/create_operator.out
src/test/regress/expected/create_procedure.out
src/test/regress/expected/create_view.out
src/test/regress/expected/domain.out
src/test/regress/expected/expressions.out
src/test/regress/expected/geometry.out
src/test/regress/expected/horology.out
src/test/regress/expected/misc_functions.out
src/test/regress/expected/multirangetypes.out
src/test/regress/expected/plpgsql.out
src/test/regress/expected/polymorphism.out
src/test/regress/expected/rangetypes.out
src/test/regress/expected/rowtypes.out
src/test/regress/expected/subselect.out
src/test/regress/expected/temp.out
src/test/regress/expected/text.out
src/test/regress/expected/time.out
src/test/regress/expected/timetz.out
src/test/regress/expected/with.out
src/test/regress/expected/xid.out
src/test/regress/sql/create_operator.sql
src/test/regress/sql/polymorphism.sql