1997-11-25 23:07:18 +01:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* parse_func.h
|
1997-11-25 23:07:18 +01:00
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
2023-01-02 21:00:37 +01:00
|
|
|
* Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1997-11-25 23:07:18 +01:00
|
|
|
*
|
2010-09-20 22:08:53 +02:00
|
|
|
* src/include/parser/parse_func.h
|
1997-11-25 23:07:18 +01:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2019-08-05 05:14:58 +02:00
|
|
|
#ifndef PARSE_FUNC_H
|
|
|
|
#define PARSE_FUNC_H
|
1997-11-25 23:07:18 +01:00
|
|
|
|
2003-05-26 02:11:29 +02:00
|
|
|
#include "catalog/namespace.h"
|
1999-07-16 01:04:24 +02:00
|
|
|
#include "parser/parse_node.h"
|
1997-11-25 23:07:18 +01:00
|
|
|
|
2003-04-30 00:13:11 +02:00
|
|
|
|
2001-10-05 00:06:46 +02:00
|
|
|
/* Result codes for func_get_detail */
|
|
|
|
typedef enum
|
|
|
|
{
|
2003-07-04 04:51:34 +02:00
|
|
|
FUNCDETAIL_NOTFOUND, /* no matching function */
|
|
|
|
FUNCDETAIL_MULTIPLE, /* too many matching functions */
|
2002-04-11 22:00:18 +02:00
|
|
|
FUNCDETAIL_NORMAL, /* found a matching regular function */
|
2017-11-30 14:46:13 +01:00
|
|
|
FUNCDETAIL_PROCEDURE, /* found a matching procedure */
|
2002-04-11 22:00:18 +02:00
|
|
|
FUNCDETAIL_AGGREGATE, /* found a matching aggregate function */
|
2008-12-28 19:54:01 +01:00
|
|
|
FUNCDETAIL_WINDOWFUNC, /* found a matching window function */
|
2001-10-05 00:06:46 +02:00
|
|
|
FUNCDETAIL_COERCION, /* it's a type coercion request */
|
|
|
|
} FuncDetailCode;
|
|
|
|
|
|
|
|
|
2013-07-17 02:15:36 +02:00
|
|
|
extern Node *ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs,
|
2017-11-30 14:46:13 +01:00
|
|
|
Node *last_srf, FuncCall *fn, bool proc_call,
|
|
|
|
int location);
|
1997-11-25 23:07:18 +01:00
|
|
|
|
2009-10-08 04:39:25 +02:00
|
|
|
extern FuncDetailCode func_get_detail(List *funcname,
|
|
|
|
List *fargs, List *fargnames,
|
2008-12-18 19:20:35 +01:00
|
|
|
int nargs, Oid *argtypes,
|
|
|
|
bool expand_variadic, bool expand_defaults,
|
Reconsider the handling of procedure OUT parameters.
Commit 2453ea142 redefined pg_proc.proargtypes to include the types of
OUT parameters, for procedures only. While that had some advantages
for implementing the SQL-spec behavior of DROP PROCEDURE, it was pretty
disastrous from a number of other perspectives. Notably, since the
primary key of pg_proc is name + proargtypes, this made it possible to
have multiple procedures with identical names + input arguments and
differing output argument types. That would make it impossible to call
any one of the procedures by writing just NULL (or "?", or any other
data-type-free notation) for the output argument(s). The change also
seems likely to cause grave confusion for client applications that
examine pg_proc and expect the traditional definition of proargtypes.
Hence, revert the definition of proargtypes to what it was, and
undo a number of complications that had been added to support that.
To support the SQL-spec behavior of DROP PROCEDURE, when there are
no argmode markers in the command's parameter list, we perform the
lookup both ways (that is, matching against both proargtypes and
proallargtypes), succeeding if we get just one unique match.
In principle this could result in ambiguous-function failures
that would not happen when using only one of the two rules.
However, overloading of procedure names is thought to be a pretty
rare usage, so this shouldn't cause many problems in practice.
Postgres-specific code such as pg_dump can defend against any
possibility of such failures by being careful to specify argmodes
for all procedure arguments.
This also fixes a few other bugs in the area of CALL statements
with named parameters, and improves the documentation a little.
catversion bump forced because the representation of procedures
with OUT arguments changes.
Discussion: https://postgr.es/m/3742981.1621533210@sss.pgh.pa.us
2021-06-10 23:11:36 +02:00
|
|
|
bool include_out_arguments,
|
2001-10-05 00:06:46 +02:00
|
|
|
Oid *funcid, Oid *rettype,
|
2013-07-18 17:52:12 +02:00
|
|
|
bool *retset, int *nvargs, Oid *vatype,
|
|
|
|
Oid **true_typeids, List **argdefaults);
|
2000-08-20 02:44:19 +02:00
|
|
|
|
2003-05-26 02:11:29 +02:00
|
|
|
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);
|
|
|
|
|
2003-04-30 00:13:11 +02:00
|
|
|
extern void make_fn_arguments(ParseState *pstate,
|
|
|
|
List *fargs,
|
2003-04-09 01:20:04 +02:00
|
|
|
Oid *actual_arg_types,
|
|
|
|
Oid *declared_arg_types);
|
|
|
|
|
2009-10-08 04:39:25 +02:00
|
|
|
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);
|
2001-10-28 07:26:15 +01:00
|
|
|
|
2003-07-04 04:51:34 +02:00
|
|
|
extern Oid LookupFuncName(List *funcname, int nargs, const Oid *argtypes,
|
2019-03-21 16:51:55 +01:00
|
|
|
bool missing_ok);
|
2017-11-30 14:46:13 +01:00
|
|
|
extern Oid LookupFuncWithArgs(ObjectType objtype, ObjectWithArgs *func,
|
2019-03-21 16:51:55 +01:00
|
|
|
bool missing_ok);
|
2002-04-09 22:35:55 +02:00
|
|
|
|
Disallow set-returning functions inside CASE or COALESCE.
When we reimplemented SRFs in commit 69f4b9c85, our initial choice was
to allow the behavior to vary from historical practice in cases where a
SRF call appeared within a conditional-execution construct (currently,
only CASE or COALESCE). But that was controversial to begin with, and
subsequent discussion has resulted in a consensus that it's better to
throw an error instead of executing the query differently from before,
so long as we can provide a reasonably clear error message and a way to
rewrite the query.
Hence, add a parser mechanism to allow detection of such cases during
parse analysis. The mechanism just requires storing, in the ParseState,
a pointer to the set-returning FuncExpr or OpExpr most recently emitted
by parse analysis. Then the parsing functions for CASE and COALESCE can
detect the presence of a SRF in their arguments by noting whether this
pointer changes while analyzing their arguments. Furthermore, if it does,
it provides a suitable error cursor location for the complaint. (This
means that if there's more than one SRF in the arguments, the error will
point at the last one to be analyzed not the first. While connoisseurs of
parsing behavior might find that odd, it's unlikely the average user would
ever notice.)
While at it, we can also provide more specific error messages than before
about some pre-existing restrictions, such as no-SRFs-within-aggregates.
Also, reject at parse time cases where a NULLIF or IS DISTINCT FROM
construct would need to return a set. We've never supported that, but the
restriction is depended on in more subtle ways now, so it seems wise to
detect it at the start.
Also, provide some documentation about how to rewrite a SRF-within-CASE
query using a custom wrapper SRF.
It turns out that the information_schema.user_mapping_options view
contained an instance of exactly the behavior we're now forbidding; but
rewriting it makes it more clear and safer too.
initdb forced because of user_mapping_options change.
Patch by me, with error message suggestions from Alvaro Herrera and
Andres Freund, pursuant to a complaint from Regina Obe.
Discussion: https://postgr.es/m/000001d2d5de$d8d66170$8a832450$@pcorp.us
2017-06-14 05:46:39 +02:00
|
|
|
extern void check_srf_call_placement(ParseState *pstate, Node *last_srf,
|
|
|
|
int location);
|
2016-09-13 19:54:24 +02:00
|
|
|
|
1997-11-25 23:07:18 +01:00
|
|
|
#endif /* PARSE_FUNC_H */
|