mirror of
https://github.com/postgres/postgres.git
synced 2025-10-15 05:46:52 +03:00
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
76 lines
2.5 KiB
C
76 lines
2.5 KiB
C
/*-------------------------------------------------------------------------
|
|
*
|
|
* parse_func.h
|
|
*
|
|
*
|
|
*
|
|
* Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
*
|
|
* src/include/parser/parse_func.h
|
|
*
|
|
*-------------------------------------------------------------------------
|
|
*/
|
|
#ifndef PARSE_FUNC_H
|
|
#define PARSE_FUNC_H
|
|
|
|
#include "catalog/namespace.h"
|
|
#include "parser/parse_node.h"
|
|
|
|
|
|
/* Result codes for func_get_detail */
|
|
typedef enum
|
|
{
|
|
FUNCDETAIL_NOTFOUND, /* no matching function */
|
|
FUNCDETAIL_MULTIPLE, /* too many matching functions */
|
|
FUNCDETAIL_NORMAL, /* found a matching regular function */
|
|
FUNCDETAIL_PROCEDURE, /* found a matching procedure */
|
|
FUNCDETAIL_AGGREGATE, /* found a matching aggregate function */
|
|
FUNCDETAIL_WINDOWFUNC, /* found a matching window function */
|
|
FUNCDETAIL_COERCION, /* it's a type coercion request */
|
|
} FuncDetailCode;
|
|
|
|
|
|
extern Node *ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs,
|
|
Node *last_srf, FuncCall *fn, bool proc_call,
|
|
int location);
|
|
|
|
extern FuncDetailCode func_get_detail(List *funcname,
|
|
List *fargs, List *fargnames,
|
|
int nargs, Oid *argtypes,
|
|
bool expand_variadic, bool expand_defaults,
|
|
bool include_out_arguments,
|
|
int *fgc_flags,
|
|
Oid *funcid, Oid *rettype,
|
|
bool *retset, int *nvargs, Oid *vatype,
|
|
Oid **true_typeids, List **argdefaults);
|
|
|
|
extern int func_match_argtypes(int nargs,
|
|
Oid *input_typeids,
|
|
FuncCandidateList raw_candidates,
|
|
FuncCandidateList *candidates);
|
|
|
|
extern FuncCandidateList func_select_candidate(int nargs,
|
|
Oid *input_typeids,
|
|
FuncCandidateList candidates);
|
|
|
|
extern void make_fn_arguments(ParseState *pstate,
|
|
List *fargs,
|
|
Oid *actual_arg_types,
|
|
Oid *declared_arg_types);
|
|
|
|
extern const char *funcname_signature_string(const char *funcname, int nargs,
|
|
List *argnames, const Oid *argtypes);
|
|
extern const char *func_signature_string(List *funcname, int nargs,
|
|
List *argnames, const Oid *argtypes);
|
|
|
|
extern Oid LookupFuncName(List *funcname, int nargs, const Oid *argtypes,
|
|
bool missing_ok);
|
|
extern Oid LookupFuncWithArgs(ObjectType objtype, ObjectWithArgs *func,
|
|
bool missing_ok);
|
|
|
|
extern void check_srf_call_placement(ParseState *pstate, Node *last_srf,
|
|
int location);
|
|
|
|
#endif /* PARSE_FUNC_H */
|