
This patch introduces generic support for ordered-set and hypothetical-set aggregate functions, as well as implementations of the instances defined in SQL:2008 (percentile_cont(), percentile_disc(), rank(), dense_rank(), percent_rank(), cume_dist()). We also added mode() though it is not in the spec, as well as versions of percentile_cont() and percentile_disc() that can compute multiple percentile values in one pass over the data. Unlike the original submission, this patch puts full control of the sorting process in the hands of the aggregate's support functions. To allow the support functions to find out how they're supposed to sort, a new API function AggGetAggref() is added to nodeAgg.c. This allows retrieval of the aggregate call's Aggref node, which may have other uses beyond the immediate need. There is also support for ordered-set aggregates to install cleanup callback functions, so that they can be sure that infrastructure such as tuplesort objects gets cleaned up. In passing, make some fixes in the recently-added support for variadic aggregates, and make some editorial adjustments in the recent FILTER additions for aggregates. Also, simplify use of IsBinaryCoercible() by allowing it to succeed whenever the target type is ANY or ANYELEMENT. It was inconsistent that it dealt with other polymorphic target types but not these. Atri Sharma and Andrew Gierth; reviewed by Pavel Stehule and Vik Fearing, and rather heavily editorialized upon by Tom Lane
83 lines
2.5 KiB
C
83 lines
2.5 KiB
C
/*-------------------------------------------------------------------------
|
|
*
|
|
* parse_func.h
|
|
*
|
|
*
|
|
*
|
|
* Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
*
|
|
* src/include/parser/parse_func.h
|
|
*
|
|
*-------------------------------------------------------------------------
|
|
*/
|
|
#ifndef PARSER_FUNC_H
|
|
#define PARSER_FUNC_H
|
|
|
|
#include "catalog/namespace.h"
|
|
#include "parser/parse_node.h"
|
|
|
|
|
|
/*
|
|
* This structure is used to explore the inheritance hierarchy above
|
|
* nodes in the type tree in order to disambiguate among polymorphic
|
|
* functions.
|
|
*/
|
|
typedef struct _InhPaths
|
|
{
|
|
int nsupers; /* number of superclasses */
|
|
Oid self; /* this class */
|
|
Oid *supervec; /* vector of superclasses */
|
|
} InhPaths;
|
|
|
|
/* 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_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,
|
|
FuncCall *fn, int location);
|
|
|
|
extern FuncDetailCode func_get_detail(List *funcname,
|
|
List *fargs, List *fargnames,
|
|
int nargs, Oid *argtypes,
|
|
bool expand_variadic, bool expand_defaults,
|
|
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 noError);
|
|
extern Oid LookupFuncNameTypeNames(List *funcname, List *argtypes,
|
|
bool noError);
|
|
extern Oid LookupAggNameTypeNames(List *aggname, List *argtypes,
|
|
bool noError);
|
|
|
|
#endif /* PARSE_FUNC_H */
|