PostgreSQL Source Code git master
Enumerations | Functions
parse_func.h File Reference
#include "catalog/namespace.h"
#include "parser/parse_node.h"
Include dependency graph for parse_func.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

 

Functions

NodeParseFuncOrColumn (ParseState *pstate, List *funcname, List *fargs, Node *last_srf, FuncCall *fn, bool proc_call, int location)
 
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)
 
int  func_match_argtypes (int nargs, Oid *input_typeids, FuncCandidateList raw_candidates, FuncCandidateList *candidates)
 
FuncCandidateList  func_select_candidate (int nargs, Oid *input_typeids, FuncCandidateList candidates)
 
void  make_fn_arguments (ParseState *pstate, List *fargs, Oid *actual_arg_types, Oid *declared_arg_types)
 
const char *  funcname_signature_string (const char *funcname, int nargs, List *argnames, const Oid *argtypes)
 
const char *  func_signature_string (List *funcname, int nargs, List *argnames, const Oid *argtypes)
 
Oid  LookupFuncName (List *funcname, int nargs, const Oid *argtypes, bool missing_ok)
 
Oid  LookupFuncWithArgs (ObjectType objtype, ObjectWithArgs *func, bool missing_ok)
 
void  check_srf_call_placement (ParseState *pstate, Node *last_srf, int location)
 

Enumeration Type Documentation

FuncDetailCode

Enumerator
FUNCDETAIL_NOTFOUND 
FUNCDETAIL_MULTIPLE 
FUNCDETAIL_NORMAL 
FUNCDETAIL_PROCEDURE 
FUNCDETAIL_AGGREGATE 
FUNCDETAIL_WINDOWFUNC 
FUNCDETAIL_COERCION 

Definition at line 22 of file parse_func.h.

23{
24 FUNCDETAIL_NOTFOUND, /* no matching function */
25 FUNCDETAIL_MULTIPLE, /* too many matching functions */
26 FUNCDETAIL_NORMAL, /* found a matching regular function */
27 FUNCDETAIL_PROCEDURE, /* found a matching procedure */
28 FUNCDETAIL_AGGREGATE, /* found a matching aggregate function */
29 FUNCDETAIL_WINDOWFUNC, /* found a matching window function */
30 FUNCDETAIL_COERCION, /* it's a type coercion request */
FuncDetailCode
Definition: parse_func.h:23
@ FUNCDETAIL_MULTIPLE
Definition: parse_func.h:25
@ FUNCDETAIL_NORMAL
Definition: parse_func.h:26
@ FUNCDETAIL_PROCEDURE
Definition: parse_func.h:27
@ FUNCDETAIL_WINDOWFUNC
Definition: parse_func.h:29
@ FUNCDETAIL_NOTFOUND
Definition: parse_func.h:24
@ FUNCDETAIL_COERCION
Definition: parse_func.h:30
@ FUNCDETAIL_AGGREGATE
Definition: parse_func.h:28

Function Documentation

check_srf_call_placement()

void check_srf_call_placement ( ParseStatepstate,
Nodelast_srf,
int  location 
)

Definition at line 2636 of file parse_func.c.

2637{
2638 const char *err;
2639 bool errkind;
2640
2641 /*
2642 * Check to see if the set-returning function is in an invalid place
2643 * within the query. Basically, we don't allow SRFs anywhere except in
2644 * the targetlist (which includes GROUP BY/ORDER BY expressions), VALUES,
2645 * and functions in FROM.
2646 *
2647 * For brevity we support two schemes for reporting an error here: set
2648 * "err" to a custom message, or set "errkind" true if the error context
2649 * is sufficiently identified by what ParseExprKindName will return, *and*
2650 * what it will return is just a SQL keyword. (Otherwise, use a custom
2651 * message to avoid creating translation problems.)
2652 */
2653 err = NULL;
2654 errkind = false;
2655 switch (pstate->p_expr_kind)
2656 {
2657 case EXPR_KIND_NONE:
2658 Assert(false); /* can't happen */
2659 break;
2660 case EXPR_KIND_OTHER:
2661 /* Accept SRF here; caller must throw error if wanted */
2662 break;
2663 case EXPR_KIND_JOIN_ON:
2665 err = _("set-returning functions are not allowed in JOIN conditions");
2666 break;
2668 /* can't get here, but just in case, throw an error */
2669 errkind = true;
2670 break;
2672 /* okay, but we don't allow nested SRFs here */
2673 /* errmsg is chosen to match transformRangeFunction() */
2674 /* errposition should point to the inner SRF */
2675 if (pstate->p_last_srf != last_srf)
2676 ereport(ERROR,
2677 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2678 errmsg("set-returning functions must appear at top level of FROM"),
2679 parser_errposition(pstate,
2680 exprLocation(pstate->p_last_srf))));
2681 break;
2682 case EXPR_KIND_WHERE:
2683 errkind = true;
2684 break;
2685 case EXPR_KIND_POLICY:
2686 err = _("set-returning functions are not allowed in policy expressions");
2687 break;
2688 case EXPR_KIND_HAVING:
2689 errkind = true;
2690 break;
2691 case EXPR_KIND_FILTER:
2692 errkind = true;
2693 break;
2696 /* okay, these are effectively GROUP BY/ORDER BY */
2697 pstate->p_hasTargetSRFs = true;
2698 break;
2702 err = _("set-returning functions are not allowed in window definitions");
2703 break;
2706 /* okay */
2707 pstate->p_hasTargetSRFs = true;
2708 break;
2711 /* disallowed because it would be ambiguous what to do */
2712 errkind = true;
2713 break;
2714 case EXPR_KIND_GROUP_BY:
2715 case EXPR_KIND_ORDER_BY:
2716 /* okay */
2717 pstate->p_hasTargetSRFs = true;
2718 break;
2720 /* okay */
2721 pstate->p_hasTargetSRFs = true;
2722 break;
2723 case EXPR_KIND_LIMIT:
2724 case EXPR_KIND_OFFSET:
2725 errkind = true;
2726 break;
2729 errkind = true;
2730 break;
2731 case EXPR_KIND_VALUES:
2732 /* SRFs are presently not supported by nodeValuesscan.c */
2733 errkind = true;
2734 break;
2736 /* okay, since we process this like a SELECT tlist */
2737 pstate->p_hasTargetSRFs = true;
2738 break;
2740 err = _("set-returning functions are not allowed in MERGE WHEN conditions");
2741 break;
2744 err = _("set-returning functions are not allowed in check constraints");
2745 break;
2748 err = _("set-returning functions are not allowed in DEFAULT expressions");
2749 break;
2751 err = _("set-returning functions are not allowed in index expressions");
2752 break;
2754 err = _("set-returning functions are not allowed in index predicates");
2755 break;
2757 err = _("set-returning functions are not allowed in statistics expressions");
2758 break;
2760 err = _("set-returning functions are not allowed in transform expressions");
2761 break;
2763 err = _("set-returning functions are not allowed in EXECUTE parameters");
2764 break;
2766 err = _("set-returning functions are not allowed in trigger WHEN conditions");
2767 break;
2769 err = _("set-returning functions are not allowed in partition bound");
2770 break;
2772 err = _("set-returning functions are not allowed in partition key expressions");
2773 break;
2775 err = _("set-returning functions are not allowed in CALL arguments");
2776 break;
2778 err = _("set-returning functions are not allowed in COPY FROM WHERE conditions");
2779 break;
2781 err = _("set-returning functions are not allowed in column generation expressions");
2782 break;
2784 errkind = true;
2785 break;
2786
2787 /*
2788 * There is intentionally no default: case here, so that the
2789 * compiler will warn if we add a new ParseExprKind without
2790 * extending this switch. If we do see an unrecognized value at
2791 * runtime, the behavior will be the same as for EXPR_KIND_OTHER,
2792 * which is sane anyway.
2793 */
2794 }
2795 if (err)
2796 ereport(ERROR,
2797 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2798 errmsg_internal("%s", err),
2799 parser_errposition(pstate, location)));
2800 if (errkind)
2801 ereport(ERROR,
2802 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2803 /* translator: %s is name of a SQL construct, eg GROUP BY */
2804 errmsg("set-returning functions are not allowed in %s",
2806 parser_errposition(pstate, location)));
2807}
int errmsg_internal(const char *fmt,...)
Definition: elog.c:1161
int errcode(int sqlerrcode)
Definition: elog.c:854
int errmsg(const char *fmt,...)
Definition: elog.c:1071
_
#define _(x)
Definition: elog.c:91
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:150
void err(int eval, const char *fmt,...)
Definition: err.c:43
Assert(PointerIsAligned(start, uint64))
int exprLocation(const Node *expr)
Definition: nodeFuncs.c:1388
const char * ParseExprKindName(ParseExprKind exprKind)
Definition: parse_expr.c:3132
int parser_errposition(ParseState *pstate, int location)
Definition: parse_node.c:106
@ EXPR_KIND_EXECUTE_PARAMETER
Definition: parse_node.h:76
@ EXPR_KIND_DOMAIN_CHECK
Definition: parse_node.h:69
@ EXPR_KIND_COPY_WHERE
Definition: parse_node.h:82
@ EXPR_KIND_COLUMN_DEFAULT
Definition: parse_node.h:70
@ EXPR_KIND_DISTINCT_ON
Definition: parse_node.h:61
@ EXPR_KIND_MERGE_WHEN
Definition: parse_node.h:58
@ EXPR_KIND_STATS_EXPRESSION
Definition: parse_node.h:74
@ EXPR_KIND_INDEX_EXPRESSION
Definition: parse_node.h:72
@ EXPR_KIND_MERGE_RETURNING
Definition: parse_node.h:65
@ EXPR_KIND_PARTITION_BOUND
Definition: parse_node.h:79
@ EXPR_KIND_FUNCTION_DEFAULT
Definition: parse_node.h:71
@ EXPR_KIND_WINDOW_FRAME_RANGE
Definition: parse_node.h:51
@ EXPR_KIND_VALUES
Definition: parse_node.h:66
@ EXPR_KIND_FROM_SUBSELECT
Definition: parse_node.h:44
@ EXPR_KIND_POLICY
Definition: parse_node.h:78
@ EXPR_KIND_WINDOW_FRAME_GROUPS
Definition: parse_node.h:53
@ EXPR_KIND_PARTITION_EXPRESSION
Definition: parse_node.h:80
@ EXPR_KIND_JOIN_USING
Definition: parse_node.h:43
@ EXPR_KIND_INDEX_PREDICATE
Definition: parse_node.h:73
@ EXPR_KIND_ORDER_BY
Definition: parse_node.h:60
@ EXPR_KIND_OFFSET
Definition: parse_node.h:63
@ EXPR_KIND_JOIN_ON
Definition: parse_node.h:42
@ EXPR_KIND_HAVING
Definition: parse_node.h:47
@ EXPR_KIND_INSERT_TARGET
Definition: parse_node.h:55
@ EXPR_KIND_ALTER_COL_TRANSFORM
Definition: parse_node.h:75
@ EXPR_KIND_LIMIT
Definition: parse_node.h:62
@ EXPR_KIND_WHERE
Definition: parse_node.h:46
@ EXPR_KIND_UPDATE_TARGET
Definition: parse_node.h:57
@ EXPR_KIND_SELECT_TARGET
Definition: parse_node.h:54
@ EXPR_KIND_RETURNING
Definition: parse_node.h:64
@ EXPR_KIND_GENERATED_COLUMN
Definition: parse_node.h:83
@ EXPR_KIND_NONE
Definition: parse_node.h:40
@ EXPR_KIND_CALL_ARGUMENT
Definition: parse_node.h:81
@ EXPR_KIND_GROUP_BY
Definition: parse_node.h:59
@ EXPR_KIND_OTHER
Definition: parse_node.h:41
@ EXPR_KIND_FROM_FUNCTION
Definition: parse_node.h:45
@ EXPR_KIND_TRIGGER_WHEN
Definition: parse_node.h:77
@ EXPR_KIND_FILTER
Definition: parse_node.h:48
@ EXPR_KIND_UPDATE_SOURCE
Definition: parse_node.h:56
@ EXPR_KIND_CHECK_CONSTRAINT
Definition: parse_node.h:68
@ EXPR_KIND_WINDOW_PARTITION
Definition: parse_node.h:49
@ EXPR_KIND_CYCLE_MARK
Definition: parse_node.h:84
@ EXPR_KIND_WINDOW_FRAME_ROWS
Definition: parse_node.h:52
@ EXPR_KIND_WINDOW_ORDER
Definition: parse_node.h:50
@ EXPR_KIND_VALUES_SINGLE
Definition: parse_node.h:67
bool p_hasTargetSRFs
Definition: parse_node.h:228
ParseExprKind p_expr_kind
Definition: parse_node.h:214
Node * p_last_srf
Definition: parse_node.h:232

References _, Assert(), ereport, err(), errcode(), errmsg(), errmsg_internal(), ERROR, EXPR_KIND_ALTER_COL_TRANSFORM, EXPR_KIND_CALL_ARGUMENT, EXPR_KIND_CHECK_CONSTRAINT, EXPR_KIND_COLUMN_DEFAULT, EXPR_KIND_COPY_WHERE, EXPR_KIND_CYCLE_MARK, EXPR_KIND_DISTINCT_ON, EXPR_KIND_DOMAIN_CHECK, EXPR_KIND_EXECUTE_PARAMETER, EXPR_KIND_FILTER, EXPR_KIND_FROM_FUNCTION, EXPR_KIND_FROM_SUBSELECT, EXPR_KIND_FUNCTION_DEFAULT, EXPR_KIND_GENERATED_COLUMN, EXPR_KIND_GROUP_BY, EXPR_KIND_HAVING, EXPR_KIND_INDEX_EXPRESSION, EXPR_KIND_INDEX_PREDICATE, EXPR_KIND_INSERT_TARGET, EXPR_KIND_JOIN_ON, EXPR_KIND_JOIN_USING, EXPR_KIND_LIMIT, EXPR_KIND_MERGE_RETURNING, EXPR_KIND_MERGE_WHEN, EXPR_KIND_NONE, EXPR_KIND_OFFSET, EXPR_KIND_ORDER_BY, EXPR_KIND_OTHER, EXPR_KIND_PARTITION_BOUND, EXPR_KIND_PARTITION_EXPRESSION, EXPR_KIND_POLICY, EXPR_KIND_RETURNING, EXPR_KIND_SELECT_TARGET, EXPR_KIND_STATS_EXPRESSION, EXPR_KIND_TRIGGER_WHEN, EXPR_KIND_UPDATE_SOURCE, EXPR_KIND_UPDATE_TARGET, EXPR_KIND_VALUES, EXPR_KIND_VALUES_SINGLE, EXPR_KIND_WHERE, EXPR_KIND_WINDOW_FRAME_GROUPS, EXPR_KIND_WINDOW_FRAME_RANGE, EXPR_KIND_WINDOW_FRAME_ROWS, EXPR_KIND_WINDOW_ORDER, EXPR_KIND_WINDOW_PARTITION, exprLocation(), ParseState::p_expr_kind, ParseState::p_hasTargetSRFs, ParseState::p_last_srf, ParseExprKindName(), and parser_errposition().

Referenced by make_op(), and ParseFuncOrColumn().

func_get_detail()

FuncDetailCode func_get_detail ( Listfuncname,
Listfargs,
Listfargnames,
int  nargs,
Oidargtypes,
bool  expand_variadic,
bool  expand_defaults,
bool  include_out_arguments,
int *  fgc_flags,
Oidfuncid,
Oidrettype,
bool *  retset,
int *  nvargs,
Oidvatype,
Oid **  true_typeids,
List **  argdefaults 
)

Definition at line 1513 of file parse_func.c.

1529{
1530 FuncCandidateList raw_candidates;
1531 FuncCandidateList best_candidate;
1532
1533 /* initialize output arguments to silence compiler warnings */
1534 *funcid = InvalidOid;
1535 *rettype = InvalidOid;
1536 *retset = false;
1537 *nvargs = 0;
1538 *vatype = InvalidOid;
1539 *true_typeids = NULL;
1540 if (argdefaults)
1541 *argdefaults = NIL;
1542
1543 /* Get list of possible candidates from namespace search */
1544 raw_candidates = FuncnameGetCandidates(funcname, nargs, fargnames,
1545 expand_variadic, expand_defaults,
1546 include_out_arguments, false,
1547 fgc_flags);
1548
1549 /*
1550 * Quickly check if there is an exact match to the input datatypes (there
1551 * can be only one)
1552 */
1553 for (best_candidate = raw_candidates;
1554 best_candidate != NULL;
1555 best_candidate = best_candidate->next)
1556 {
1557 /* if nargs==0, argtypes can be null; don't pass that to memcmp */
1558 if (nargs == 0 ||
1559 memcmp(argtypes, best_candidate->args, nargs * sizeof(Oid)) == 0)
1560 break;
1561 }
1562
1563 if (best_candidate == NULL)
1564 {
1565 /*
1566 * If we didn't find an exact match, next consider the possibility
1567 * that this is really a type-coercion request: a single-argument
1568 * function call where the function name is a type name. If so, and
1569 * if the coercion path is RELABELTYPE or COERCEVIAIO, then go ahead
1570 * and treat the "function call" as a coercion.
1571 *
1572 * This interpretation needs to be given higher priority than
1573 * interpretations involving a type coercion followed by a function
1574 * call, otherwise we can produce surprising results. For example, we
1575 * want "text(varchar)" to be interpreted as a simple coercion, not as
1576 * "text(name(varchar))" which the code below this point is entirely
1577 * capable of selecting.
1578 *
1579 * We also treat a coercion of a previously-unknown-type literal
1580 * constant to a specific type this way.
1581 *
1582 * The reason we reject COERCION_PATH_FUNC here is that we expect the
1583 * cast implementation function to be named after the target type.
1584 * Thus the function will be found by normal lookup if appropriate.
1585 *
1586 * The reason we reject COERCION_PATH_ARRAYCOERCE is mainly that you
1587 * can't write "foo[] (something)" as a function call. In theory
1588 * someone might want to invoke it as "_foo (something)" but we have
1589 * never supported that historically, so we can insist that people
1590 * write it as a normal cast instead.
1591 *
1592 * We also reject the specific case of COERCEVIAIO for a composite
1593 * source type and a string-category target type. This is a case that
1594 * find_coercion_pathway() allows by default, but experience has shown
1595 * that it's too commonly invoked by mistake. So, again, insist that
1596 * people use cast syntax if they want to do that.
1597 *
1598 * NB: it's important that this code does not exceed what coerce_type
1599 * can do, because the caller will try to apply coerce_type if we
1600 * return FUNCDETAIL_COERCION. If we return that result for something
1601 * coerce_type can't handle, we'll cause infinite recursion between
1602 * this module and coerce_type!
1603 */
1604 if (nargs == 1 && fargs != NIL && fargnames == NIL)
1605 {
1606 Oid targetType = FuncNameAsType(funcname);
1607
1608 if (OidIsValid(targetType))
1609 {
1610 Oid sourceType = argtypes[0];
1611 Node *arg1 = linitial(fargs);
1612 bool iscoercion;
1613
1614 if (sourceType == UNKNOWNOID && IsA(arg1, Const))
1615 {
1616 /* always treat typename('literal') as coercion */
1617 iscoercion = true;
1618 }
1619 else
1620 {
1621 CoercionPathType cpathtype;
1622 Oid cfuncid;
1623
1624 cpathtype = find_coercion_pathway(targetType, sourceType,
1626 &cfuncid);
1627 switch (cpathtype)
1628 {
1630 iscoercion = true;
1631 break;
1633 if ((sourceType == RECORDOID ||
1634 ISCOMPLEX(sourceType)) &&
1635 TypeCategory(targetType) == TYPCATEGORY_STRING)
1636 iscoercion = false;
1637 else
1638 iscoercion = true;
1639 break;
1640 default:
1641 iscoercion = false;
1642 break;
1643 }
1644 }
1645
1646 if (iscoercion)
1647 {
1648 /* Treat it as a type coercion */
1649 *funcid = InvalidOid;
1650 *rettype = targetType;
1651 *retset = false;
1652 *nvargs = 0;
1653 *vatype = InvalidOid;
1654 *true_typeids = argtypes;
1655 return FUNCDETAIL_COERCION;
1656 }
1657 }
1658 }
1659
1660 /*
1661 * didn't find an exact match, so now try to match up candidates...
1662 */
1663 if (raw_candidates != NULL)
1664 {
1665 FuncCandidateList current_candidates;
1666 int ncandidates;
1667
1668 ncandidates = func_match_argtypes(nargs,
1669 argtypes,
1670 raw_candidates,
1671 &current_candidates);
1672
1673 /* one match only? then run with it... */
1674 if (ncandidates == 1)
1675 best_candidate = current_candidates;
1676
1677 /*
1678 * multiple candidates? then better decide or throw an error...
1679 */
1680 else if (ncandidates > 1)
1681 {
1682 best_candidate = func_select_candidate(nargs,
1683 argtypes,
1684 current_candidates);
1685
1686 /*
1687 * If we were able to choose a best candidate, we're done.
1688 * Otherwise, ambiguous function call.
1689 */
1690 if (!best_candidate)
1691 return FUNCDETAIL_MULTIPLE;
1692 }
1693 }
1694 }
1695
1696 if (best_candidate)
1697 {
1698 HeapTuple ftup;
1699 Form_pg_proc pform;
1700 FuncDetailCode result;
1701
1702 /*
1703 * If processing named args or expanding variadics or defaults, the
1704 * "best candidate" might represent multiple equivalently good
1705 * functions; treat this case as ambiguous.
1706 */
1707 if (!OidIsValid(best_candidate->oid))
1708 return FUNCDETAIL_MULTIPLE;
1709
1710 /*
1711 * We disallow VARIADIC with named arguments unless the last argument
1712 * (the one with VARIADIC attached) actually matched the variadic
1713 * parameter. This is mere pedantry, really, but some folks insisted.
1714 */
1715 if (fargnames != NIL && !expand_variadic && nargs > 0 &&
1716 best_candidate->argnumbers[nargs - 1] != nargs - 1)
1717 {
1718 *fgc_flags |= FGC_VARIADIC_FAIL;
1719 return FUNCDETAIL_NOTFOUND;
1720 }
1721
1722 *funcid = best_candidate->oid;
1723 *nvargs = best_candidate->nvargs;
1724 *true_typeids = best_candidate->args;
1725
1726 /*
1727 * If processing named args, return actual argument positions into
1728 * NamedArgExpr nodes in the fargs list. This is a bit ugly but not
1729 * worth the extra notation needed to do it differently.
1730 */
1731 if (best_candidate->argnumbers != NULL)
1732 {
1733 int i = 0;
1734 ListCell *lc;
1735
1736 foreach(lc, fargs)
1737 {
1738 NamedArgExpr *na = (NamedArgExpr *) lfirst(lc);
1739
1740 if (IsA(na, NamedArgExpr))
1741 na->argnumber = best_candidate->argnumbers[i];
1742 i++;
1743 }
1744 }
1745
1746 ftup = SearchSysCache1(PROCOID,
1747 ObjectIdGetDatum(best_candidate->oid));
1748 if (!HeapTupleIsValid(ftup)) /* should not happen */
1749 elog(ERROR, "cache lookup failed for function %u",
1750 best_candidate->oid);
1751 pform = (Form_pg_proc) GETSTRUCT(ftup);
1752 *rettype = pform->prorettype;
1753 *retset = pform->proretset;
1754 *vatype = pform->provariadic;
1755 /* fetch default args if caller wants 'em */
1756 if (argdefaults && best_candidate->ndargs > 0)
1757 {
1758 Datum proargdefaults;
1759 char *str;
1760 List *defaults;
1761
1762 /* shouldn't happen, FuncnameGetCandidates messed up */
1763 if (best_candidate->ndargs > pform->pronargdefaults)
1764 elog(ERROR, "not enough default arguments");
1765
1766 proargdefaults = SysCacheGetAttrNotNull(PROCOID, ftup,
1767 Anum_pg_proc_proargdefaults);
1768 str = TextDatumGetCString(proargdefaults);
1769 defaults = castNode(List, stringToNode(str));
1770 pfree(str);
1771
1772 /* Delete any unused defaults from the returned list */
1773 if (best_candidate->argnumbers != NULL)
1774 {
1775 /*
1776 * This is a bit tricky in named notation, since the supplied
1777 * arguments could replace any subset of the defaults. We
1778 * work by making a bitmapset of the argnumbers of defaulted
1779 * arguments, then scanning the defaults list and selecting
1780 * the needed items. (This assumes that defaulted arguments
1781 * should be supplied in their positional order.)
1782 */
1783 Bitmapset *defargnumbers;
1784 int *firstdefarg;
1785 List *newdefaults;
1786 ListCell *lc;
1787 int i;
1788
1789 defargnumbers = NULL;
1790 firstdefarg = &best_candidate->argnumbers[best_candidate->nargs - best_candidate->ndargs];
1791 for (i = 0; i < best_candidate->ndargs; i++)
1792 defargnumbers = bms_add_member(defargnumbers,
1793 firstdefarg[i]);
1794 newdefaults = NIL;
1795 i = best_candidate->nominalnargs - pform->pronargdefaults;
1796 foreach(lc, defaults)
1797 {
1798 if (bms_is_member(i, defargnumbers))
1799 newdefaults = lappend(newdefaults, lfirst(lc));
1800 i++;
1801 }
1802 Assert(list_length(newdefaults) == best_candidate->ndargs);
1803 bms_free(defargnumbers);
1804 *argdefaults = newdefaults;
1805 }
1806 else
1807 {
1808 /*
1809 * Defaults for positional notation are lots easier; just
1810 * remove any unwanted ones from the front.
1811 */
1812 int ndelete;
1813
1814 ndelete = list_length(defaults) - best_candidate->ndargs;
1815 if (ndelete > 0)
1816 defaults = list_delete_first_n(defaults, ndelete);
1817 *argdefaults = defaults;
1818 }
1819 }
1820
1821 switch (pform->prokind)
1822 {
1823 case PROKIND_AGGREGATE:
1824 result = FUNCDETAIL_AGGREGATE;
1825 break;
1826 case PROKIND_FUNCTION:
1827 result = FUNCDETAIL_NORMAL;
1828 break;
1829 case PROKIND_PROCEDURE:
1830 result = FUNCDETAIL_PROCEDURE;
1831 break;
1832 case PROKIND_WINDOW:
1833 result = FUNCDETAIL_WINDOWFUNC;
1834 break;
1835 default:
1836 elog(ERROR, "unrecognized prokind: %c", pform->prokind);
1837 result = FUNCDETAIL_NORMAL; /* keep compiler quiet */
1838 break;
1839 }
1840
1841 ReleaseSysCache(ftup);
1842 return result;
1843 }
1844
1845 return FUNCDETAIL_NOTFOUND;
1846}
void bms_free(Bitmapset *a)
Definition: bitmapset.c:239
bool bms_is_member(int x, const Bitmapset *a)
Definition: bitmapset.c:510
Bitmapset * bms_add_member(Bitmapset *a, int x)
Definition: bitmapset.c:815
#define TextDatumGetCString(d)
Definition: builtins.h:98
#define OidIsValid(objectId)
Definition: c.h:774
#define elog(elevel,...)
Definition: elog.h:226
const char * str
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
static void * GETSTRUCT(const HeapTupleData *tuple)
Definition: htup_details.h:728
#define funcname
Definition: indent_codes.h:69
i
int i
Definition: isn.c:77
List * lappend(List *list, void *datum)
Definition: list.c:339
List * list_delete_first_n(List *list, int n)
Definition: list.c:983
void pfree(void *pointer)
Definition: mcxt.c:1594
FuncCandidateList FuncnameGetCandidates(List *names, int nargs, List *argnames, bool expand_variadic, bool expand_defaults, bool include_out_arguments, bool missing_ok, int *fgc_flags)
Definition: namespace.c:1197
#define FGC_VARIADIC_FAIL
Definition: namespace.h:58
#define IsA(nodeptr, _type_)
Definition: nodes.h:164
#define castNode(_type_, nodeptr)
Definition: nodes.h:182
TYPCATEGORY TypeCategory(Oid type)
Definition: parse_coerce.c:2976
CoercionPathType find_coercion_pathway(Oid targetTypeId, Oid sourceTypeId, CoercionContext ccontext, Oid *funcid)
Definition: parse_coerce.c:3153
CoercionPathType
Definition: parse_coerce.h:25
@ COERCION_PATH_COERCEVIAIO
Definition: parse_coerce.h:30
@ COERCION_PATH_RELABELTYPE
Definition: parse_coerce.h:28
FuncCandidateList func_select_candidate(int nargs, Oid *input_typeids, FuncCandidateList candidates)
Definition: parse_func.c:1121
static Oid FuncNameAsType(List *funcname)
Definition: parse_func.c:2004
int func_match_argtypes(int nargs, Oid *input_typeids, FuncCandidateList raw_candidates, FuncCandidateList *candidates)
Definition: parse_func.c:1036
#define ISCOMPLEX(typeid)
Definition: parse_type.h:59
#define lfirst(lc)
Definition: pg_list.h:172
static int list_length(const List *l)
Definition: pg_list.h:152
#define NIL
Definition: pg_list.h:68
#define linitial(l)
Definition: pg_list.h:178
FormData_pg_proc * Form_pg_proc
Definition: pg_proc.h:136
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:262
uint64_t Datum
Definition: postgres.h:70
#define InvalidOid
Definition: postgres_ext.h:37
unsigned int Oid
Definition: postgres_ext.h:32
@ COERCION_EXPLICIT
Definition: primnodes.h:749
void * stringToNode(const char *str)
Definition: read.c:90
Definition: primnodes.h:324
Definition: pg_list.h:54
int argnumber
Definition: primnodes.h:827
Definition: nodes.h:135
int * argnumbers
Definition: namespace.h:38
struct _FuncCandidateList * next
Definition: namespace.h:31
Oid args[FLEXIBLE_ARRAY_MEMBER]
Definition: namespace.h:39
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:264
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:220
Datum SysCacheGetAttrNotNull(int cacheId, HeapTuple tup, AttrNumber attributeNumber)
Definition: syscache.c:625
Definition: pg_list.h:46

References NamedArgExpr::argnumber, _FuncCandidateList::argnumbers, _FuncCandidateList::args, Assert(), bms_add_member(), bms_free(), bms_is_member(), castNode, COERCION_EXPLICIT, COERCION_PATH_COERCEVIAIO, COERCION_PATH_RELABELTYPE, elog, ERROR, FGC_VARIADIC_FAIL, find_coercion_pathway(), func_match_argtypes(), func_select_candidate(), FUNCDETAIL_AGGREGATE, FUNCDETAIL_COERCION, FUNCDETAIL_MULTIPLE, FUNCDETAIL_NORMAL, FUNCDETAIL_NOTFOUND, FUNCDETAIL_PROCEDURE, FUNCDETAIL_WINDOWFUNC, funcname, FuncNameAsType(), FuncnameGetCandidates(), GETSTRUCT(), HeapTupleIsValid, i, InvalidOid, IsA, ISCOMPLEX, lappend(), lfirst, linitial, list_delete_first_n(), list_length(), _FuncCandidateList::nargs, _FuncCandidateList::ndargs, _FuncCandidateList::next, NIL, _FuncCandidateList::nominalnargs, _FuncCandidateList::nvargs, ObjectIdGetDatum(), _FuncCandidateList::oid, OidIsValid, pfree(), ReleaseSysCache(), SearchSysCache1(), str, stringToNode(), SysCacheGetAttrNotNull(), TextDatumGetCString, and TypeCategory().

Referenced by generate_function_name(), lookup_agg_function(), and ParseFuncOrColumn().

func_match_argtypes()

int func_match_argtypes ( int  nargs,
Oidinput_typeids,
FuncCandidateList  raw_candidates,
FuncCandidateListcandidates 
)

Definition at line 1036 of file parse_func.c.

1040{
1041 FuncCandidateList current_candidate;
1042 FuncCandidateList next_candidate;
1043 int ncandidates = 0;
1044
1045 *candidates = NULL;
1046
1047 for (current_candidate = raw_candidates;
1048 current_candidate != NULL;
1049 current_candidate = next_candidate)
1050 {
1051 next_candidate = current_candidate->next;
1052 if (can_coerce_type(nargs, input_typeids, current_candidate->args,
1054 {
1055 current_candidate->next = *candidates;
1056 *candidates = current_candidate;
1057 ncandidates++;
1058 }
1059 }
1060
1061 return ncandidates;
1062} /* func_match_argtypes() */
bool can_coerce_type(int nargs, const Oid *input_typeids, const Oid *target_typeids, CoercionContext ccontext)
Definition: parse_coerce.c:557
@ COERCION_IMPLICIT
Definition: primnodes.h:746

References _FuncCandidateList::args, can_coerce_type(), COERCION_IMPLICIT, and _FuncCandidateList::next.

Referenced by func_get_detail(), and oper_select_candidate().

func_select_candidate()

FuncCandidateList func_select_candidate ( int  nargs,
Oidinput_typeids,
FuncCandidateList  candidates 
)

Definition at line 1121 of file parse_func.c.

1124{
1125 FuncCandidateList current_candidate,
1126 first_candidate,
1127 last_candidate;
1128 Oid *current_typeids;
1129 Oid current_type;
1130 int i;
1131 int ncandidates;
1132 int nbestMatch,
1133 nmatch,
1134 nunknowns;
1135 Oid input_base_typeids[FUNC_MAX_ARGS];
1136 TYPCATEGORY slot_category[FUNC_MAX_ARGS],
1137 current_category;
1138 bool current_is_preferred;
1139 bool slot_has_preferred_type[FUNC_MAX_ARGS];
1140 bool resolved_unknowns;
1141
1142 /* protect local fixed-size arrays */
1143 if (nargs > FUNC_MAX_ARGS)
1144 ereport(ERROR,
1145 (errcode(ERRCODE_TOO_MANY_ARGUMENTS),
1146 errmsg_plural("cannot pass more than %d argument to a function",
1147 "cannot pass more than %d arguments to a function",
1149 FUNC_MAX_ARGS)));
1150
1151 /*
1152 * If any input types are domains, reduce them to their base types. This
1153 * ensures that we will consider functions on the base type to be "exact
1154 * matches" in the exact-match heuristic; it also makes it possible to do
1155 * something useful with the type-category heuristics. Note that this
1156 * makes it difficult, but not impossible, to use functions declared to
1157 * take a domain as an input datatype. Such a function will be selected
1158 * over the base-type function only if it is an exact match at all
1159 * argument positions, and so was already chosen by our caller.
1160 *
1161 * While we're at it, count the number of unknown-type arguments for use
1162 * later.
1163 */
1164 nunknowns = 0;
1165 for (i = 0; i < nargs; i++)
1166 {
1167 if (input_typeids[i] != UNKNOWNOID)
1168 input_base_typeids[i] = getBaseType(input_typeids[i]);
1169 else
1170 {
1171 /* no need to call getBaseType on UNKNOWNOID */
1172 input_base_typeids[i] = UNKNOWNOID;
1173 nunknowns++;
1174 }
1175 }
1176
1177 /*
1178 * Run through all candidates and keep those with the most matches on
1179 * exact types. Keep all candidates if none match.
1180 */
1181 ncandidates = 0;
1182 nbestMatch = 0;
1183 last_candidate = NULL;
1184 for (current_candidate = candidates;
1185 current_candidate != NULL;
1186 current_candidate = current_candidate->next)
1187 {
1188 current_typeids = current_candidate->args;
1189 nmatch = 0;
1190 for (i = 0; i < nargs; i++)
1191 {
1192 if (input_base_typeids[i] != UNKNOWNOID &&
1193 current_typeids[i] == input_base_typeids[i])
1194 nmatch++;
1195 }
1196
1197 /* take this one as the best choice so far? */
1198 if ((nmatch > nbestMatch) || (last_candidate == NULL))
1199 {
1200 nbestMatch = nmatch;
1201 candidates = current_candidate;
1202 last_candidate = current_candidate;
1203 ncandidates = 1;
1204 }
1205 /* no worse than the last choice, so keep this one too? */
1206 else if (nmatch == nbestMatch)
1207 {
1208 last_candidate->next = current_candidate;
1209 last_candidate = current_candidate;
1210 ncandidates++;
1211 }
1212 /* otherwise, don't bother keeping this one... */
1213 }
1214
1215 if (last_candidate) /* terminate rebuilt list */
1216 last_candidate->next = NULL;
1217
1218 if (ncandidates == 1)
1219 return candidates;
1220
1221 /*
1222 * Still too many candidates? Now look for candidates which have either
1223 * exact matches or preferred types at the args that will require
1224 * coercion. (Restriction added in 7.4: preferred type must be of same
1225 * category as input type; give no preference to cross-category
1226 * conversions to preferred types.) Keep all candidates if none match.
1227 */
1228 for (i = 0; i < nargs; i++) /* avoid multiple lookups */
1229 slot_category[i] = TypeCategory(input_base_typeids[i]);
1230 ncandidates = 0;
1231 nbestMatch = 0;
1232 last_candidate = NULL;
1233 for (current_candidate = candidates;
1234 current_candidate != NULL;
1235 current_candidate = current_candidate->next)
1236 {
1237 current_typeids = current_candidate->args;
1238 nmatch = 0;
1239 for (i = 0; i < nargs; i++)
1240 {
1241 if (input_base_typeids[i] != UNKNOWNOID)
1242 {
1243 if (current_typeids[i] == input_base_typeids[i] ||
1244 IsPreferredType(slot_category[i], current_typeids[i]))
1245 nmatch++;
1246 }
1247 }
1248
1249 if ((nmatch > nbestMatch) || (last_candidate == NULL))
1250 {
1251 nbestMatch = nmatch;
1252 candidates = current_candidate;
1253 last_candidate = current_candidate;
1254 ncandidates = 1;
1255 }
1256 else if (nmatch == nbestMatch)
1257 {
1258 last_candidate->next = current_candidate;
1259 last_candidate = current_candidate;
1260 ncandidates++;
1261 }
1262 }
1263
1264 if (last_candidate) /* terminate rebuilt list */
1265 last_candidate->next = NULL;
1266
1267 if (ncandidates == 1)
1268 return candidates;
1269
1270 /*
1271 * Still too many candidates? Try assigning types for the unknown inputs.
1272 *
1273 * If there are no unknown inputs, we have no more heuristics that apply,
1274 * and must fail.
1275 */
1276 if (nunknowns == 0)
1277 return NULL; /* failed to select a best candidate */
1278
1279 /*
1280 * The next step examines each unknown argument position to see if we can
1281 * determine a "type category" for it. If any candidate has an input
1282 * datatype of STRING category, use STRING category (this bias towards
1283 * STRING is appropriate since unknown-type literals look like strings).
1284 * Otherwise, if all the candidates agree on the type category of this
1285 * argument position, use that category. Otherwise, fail because we
1286 * cannot determine a category.
1287 *
1288 * If we are able to determine a type category, also notice whether any of
1289 * the candidates takes a preferred datatype within the category.
1290 *
1291 * Having completed this examination, remove candidates that accept the
1292 * wrong category at any unknown position. Also, if at least one
1293 * candidate accepted a preferred type at a position, remove candidates
1294 * that accept non-preferred types. If just one candidate remains, return
1295 * that one. However, if this rule turns out to reject all candidates,
1296 * keep them all instead.
1297 */
1298 resolved_unknowns = false;
1299 for (i = 0; i < nargs; i++)
1300 {
1301 bool have_conflict;
1302
1303 if (input_base_typeids[i] != UNKNOWNOID)
1304 continue;
1305 resolved_unknowns = true; /* assume we can do it */
1306 slot_category[i] = TYPCATEGORY_INVALID;
1307 slot_has_preferred_type[i] = false;
1308 have_conflict = false;
1309 for (current_candidate = candidates;
1310 current_candidate != NULL;
1311 current_candidate = current_candidate->next)
1312 {
1313 current_typeids = current_candidate->args;
1314 current_type = current_typeids[i];
1315 get_type_category_preferred(current_type,
1316 &current_category,
1317 &current_is_preferred);
1318 if (slot_category[i] == TYPCATEGORY_INVALID)
1319 {
1320 /* first candidate */
1321 slot_category[i] = current_category;
1322 slot_has_preferred_type[i] = current_is_preferred;
1323 }
1324 else if (current_category == slot_category[i])
1325 {
1326 /* more candidates in same category */
1327 slot_has_preferred_type[i] |= current_is_preferred;
1328 }
1329 else
1330 {
1331 /* category conflict! */
1332 if (current_category == TYPCATEGORY_STRING)
1333 {
1334 /* STRING always wins if available */
1335 slot_category[i] = current_category;
1336 slot_has_preferred_type[i] = current_is_preferred;
1337 }
1338 else
1339 {
1340 /*
1341 * Remember conflict, but keep going (might find STRING)
1342 */
1343 have_conflict = true;
1344 }
1345 }
1346 }
1347 if (have_conflict && slot_category[i] != TYPCATEGORY_STRING)
1348 {
1349 /* Failed to resolve category conflict at this position */
1350 resolved_unknowns = false;
1351 break;
1352 }
1353 }
1354
1355 if (resolved_unknowns)
1356 {
1357 /* Strip non-matching candidates */
1358 ncandidates = 0;
1359 first_candidate = candidates;
1360 last_candidate = NULL;
1361 for (current_candidate = candidates;
1362 current_candidate != NULL;
1363 current_candidate = current_candidate->next)
1364 {
1365 bool keepit = true;
1366
1367 current_typeids = current_candidate->args;
1368 for (i = 0; i < nargs; i++)
1369 {
1370 if (input_base_typeids[i] != UNKNOWNOID)
1371 continue;
1372 current_type = current_typeids[i];
1373 get_type_category_preferred(current_type,
1374 &current_category,
1375 &current_is_preferred);
1376 if (current_category != slot_category[i])
1377 {
1378 keepit = false;
1379 break;
1380 }
1381 if (slot_has_preferred_type[i] && !current_is_preferred)
1382 {
1383 keepit = false;
1384 break;
1385 }
1386 }
1387 if (keepit)
1388 {
1389 /* keep this candidate */
1390 last_candidate = current_candidate;
1391 ncandidates++;
1392 }
1393 else
1394 {
1395 /* forget this candidate */
1396 if (last_candidate)
1397 last_candidate->next = current_candidate->next;
1398 else
1399 first_candidate = current_candidate->next;
1400 }
1401 }
1402
1403 /* if we found any matches, restrict our attention to those */
1404 if (last_candidate)
1405 {
1406 candidates = first_candidate;
1407 /* terminate rebuilt list */
1408 last_candidate->next = NULL;
1409 }
1410
1411 if (ncandidates == 1)
1412 return candidates;
1413 }
1414
1415 /*
1416 * Last gasp: if there are both known- and unknown-type inputs, and all
1417 * the known types are the same, assume the unknown inputs are also that
1418 * type, and see if that gives us a unique match. If so, use that match.
1419 *
1420 * NOTE: for a binary operator with one unknown and one non-unknown input,
1421 * we already tried this heuristic in binary_oper_exact(). However, that
1422 * code only finds exact matches, whereas here we will handle matches that
1423 * involve coercion, polymorphic type resolution, etc.
1424 */
1425 if (nunknowns < nargs)
1426 {
1427 Oid known_type = UNKNOWNOID;
1428
1429 for (i = 0; i < nargs; i++)
1430 {
1431 if (input_base_typeids[i] == UNKNOWNOID)
1432 continue;
1433 if (known_type == UNKNOWNOID) /* first known arg? */
1434 known_type = input_base_typeids[i];
1435 else if (known_type != input_base_typeids[i])
1436 {
1437 /* oops, not all match */
1438 known_type = UNKNOWNOID;
1439 break;
1440 }
1441 }
1442
1443 if (known_type != UNKNOWNOID)
1444 {
1445 /* okay, just one known type, apply the heuristic */
1446 for (i = 0; i < nargs; i++)
1447 input_base_typeids[i] = known_type;
1448 ncandidates = 0;
1449 last_candidate = NULL;
1450 for (current_candidate = candidates;
1451 current_candidate != NULL;
1452 current_candidate = current_candidate->next)
1453 {
1454 current_typeids = current_candidate->args;
1455 if (can_coerce_type(nargs, input_base_typeids, current_typeids,
1457 {
1458 if (++ncandidates > 1)
1459 break; /* not unique, give up */
1460 last_candidate = current_candidate;
1461 }
1462 }
1463 if (ncandidates == 1)
1464 {
1465 /* successfully identified a unique match */
1466 last_candidate->next = NULL;
1467 return last_candidate;
1468 }
1469 }
1470 }
1471
1472 return NULL; /* failed to select a best candidate */
1473} /* func_select_candidate() */
int errmsg_plural(const char *fmt_singular, const char *fmt_plural, unsigned long n,...)
Definition: elog.c:1184
Oid getBaseType(Oid typid)
Definition: lsyscache.c:2688
void get_type_category_preferred(Oid typid, char *typcategory, bool *typispreferred)
Definition: lsyscache.c:2877
bool IsPreferredType(TYPCATEGORY category, Oid type)
Definition: parse_coerce.c:2995
char TYPCATEGORY
Definition: parse_coerce.h:21
#define FUNC_MAX_ARGS

References _FuncCandidateList::args, can_coerce_type(), COERCION_IMPLICIT, ereport, errcode(), errmsg_plural(), ERROR, FUNC_MAX_ARGS, get_type_category_preferred(), getBaseType(), i, IsPreferredType(), _FuncCandidateList::next, and TypeCategory().

Referenced by func_get_detail(), and oper_select_candidate().

func_signature_string()

const char * func_signature_string ( Listfuncname,
int  nargs,
Listargnames,
const Oidargtypes 
)

Definition at line 2153 of file parse_func.c.

2155{
2157 nargs, argnames, argtypes);
2158}
char * NameListToString(const List *names)
Definition: namespace.c:3664
const char * funcname_signature_string(const char *funcname, int nargs, List *argnames, const Oid *argtypes)
Definition: parse_func.c:2116

References funcname, funcname_signature_string(), and NameListToString().

Referenced by findRangeCanonicalFunction(), findRangeSubtypeDiffFunction(), findTypeAnalyzeFunction(), findTypeInputFunction(), findTypeOutputFunction(), findTypeReceiveFunction(), findTypeSendFunction(), findTypeSubscriptingFunction(), findTypeTypmodinFunction(), findTypeTypmodoutFunction(), get_ts_parser_func(), get_ts_template_func(), interpret_func_support(), lookup_agg_function(), LookupFuncName(), LookupFuncWithArgs(), and ParseFuncOrColumn().

funcname_signature_string()

const char * funcname_signature_string ( const char *  funcname,
int  nargs,
Listargnames,
const Oidargtypes 
)

Definition at line 2116 of file parse_func.c.

2118{
2119 StringInfoData argbuf;
2120 int numposargs;
2121 ListCell *lc;
2122 int i;
2123
2124 initStringInfo(&argbuf);
2125
2126 appendStringInfo(&argbuf, "%s(", funcname);
2127
2128 numposargs = nargs - list_length(argnames);
2129 lc = list_head(argnames);
2130
2131 for (i = 0; i < nargs; i++)
2132 {
2133 if (i)
2134 appendStringInfoString(&argbuf, ", ");
2135 if (i >= numposargs)
2136 {
2137 appendStringInfo(&argbuf, "%s => ", (char *) lfirst(lc));
2138 lc = lnext(argnames, lc);
2139 }
2140 appendStringInfoString(&argbuf, format_type_be(argtypes[i]));
2141 }
2142
2143 appendStringInfoChar(&argbuf, ')');
2144
2145 return argbuf.data; /* return palloc'd string buffer */
2146}
char * format_type_be(Oid type_oid)
Definition: format_type.c:343
static ListCell * list_head(const List *l)
Definition: pg_list.h:128
static ListCell * lnext(const List *l, const ListCell *c)
Definition: pg_list.h:343
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:145
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:230
void appendStringInfoChar(StringInfo str, char ch)
Definition: stringinfo.c:242
void initStringInfo(StringInfo str)
Definition: stringinfo.c:97
char * data
Definition: stringinfo.h:48

References appendStringInfo(), appendStringInfoChar(), appendStringInfoString(), StringInfoData::data, format_type_be(), funcname, i, initStringInfo(), lfirst, list_head(), list_length(), and lnext().

Referenced by func_signature_string(), and IsThereFunctionInNamespace().

LookupFuncName()

Oid LookupFuncName ( Listfuncname,
int  nargs,
const Oidargtypes,
bool  missing_ok 
)

Definition at line 2269 of file parse_func.c.

2270{
2271 Oid funcoid;
2272 FuncLookupError lookupError;
2273
2275 funcname, nargs, argtypes,
2276 false, missing_ok,
2277 &lookupError);
2278
2279 if (OidIsValid(funcoid))
2280 return funcoid;
2281
2282 switch (lookupError)
2283 {
2285 /* Let the caller deal with it when missing_ok is true */
2286 if (missing_ok)
2287 return InvalidOid;
2288
2289 if (nargs < 0)
2290 ereport(ERROR,
2291 (errcode(ERRCODE_UNDEFINED_FUNCTION),
2292 errmsg("could not find a function named \"%s\"",
2294 else
2295 ereport(ERROR,
2296 (errcode(ERRCODE_UNDEFINED_FUNCTION),
2297 errmsg("function %s does not exist",
2299 NIL, argtypes))));
2300 break;
2301
2303 /* Raise an error regardless of missing_ok */
2304 ereport(ERROR,
2305 (errcode(ERRCODE_AMBIGUOUS_FUNCTION),
2306 errmsg("function name \"%s\" is not unique",
2308 errhint("Specify the argument list to select the function unambiguously.")));
2309 break;
2310 }
2311
2312 return InvalidOid; /* Keep compiler quiet */
2313}
int errhint(const char *fmt,...)
Definition: elog.c:1321
static Oid LookupFuncNameInternal(ObjectType objtype, List *funcname, int nargs, const Oid *argtypes, bool include_out_arguments, bool missing_ok, FuncLookupError *lookupError)
Definition: parse_func.c:2172
const char * func_signature_string(List *funcname, int nargs, List *argnames, const Oid *argtypes)
Definition: parse_func.c:2153
FuncLookupError
Definition: parse_func.c:40
@ FUNCLOOKUP_NOSUCHFUNC
Definition: parse_func.c:41
@ FUNCLOOKUP_AMBIGUOUS
Definition: parse_func.c:42
@ OBJECT_FUNCTION
Definition: parsenodes.h:2344

References ereport, errcode(), errhint(), errmsg(), ERROR, func_signature_string(), FUNCLOOKUP_AMBIGUOUS, FUNCLOOKUP_NOSUCHFUNC, funcname, InvalidOid, LookupFuncNameInternal(), NameListToString(), NIL, OBJECT_FUNCTION, and OidIsValid.

Referenced by call_pltcl_start_proc(), CreateConversionCommand(), CreateEventTrigger(), CreateProceduralLanguage(), CreateTriggerFiringOn(), DefineOperator(), findRangeCanonicalFunction(), findRangeSubtypeDiffFunction(), findTypeAnalyzeFunction(), findTypeInputFunction(), findTypeOutputFunction(), findTypeReceiveFunction(), findTypeSendFunction(), findTypeSubscriptingFunction(), findTypeTypmodinFunction(), findTypeTypmodoutFunction(), get_ts_parser_func(), get_ts_template_func(), interpret_func_support(), lookup_am_handler_func(), lookup_fdw_handler_func(), lookup_fdw_validator_func(), transformRangeTableSample(), ValidateJoinEstimator(), and ValidateRestrictionEstimator().

LookupFuncWithArgs()

Oid LookupFuncWithArgs ( ObjectType  objtype,
ObjectWithArgsfunc,
bool  missing_ok 
)

Definition at line 2331 of file parse_func.c.

2332{
2333 Oid argoids[FUNC_MAX_ARGS];
2334 int argcount;
2335 int nargs;
2336 int i;
2337 ListCell *args_item;
2338 Oid oid;
2339 FuncLookupError lookupError;
2340
2341 Assert(objtype == OBJECT_AGGREGATE ||
2342 objtype == OBJECT_FUNCTION ||
2343 objtype == OBJECT_PROCEDURE ||
2344 objtype == OBJECT_ROUTINE);
2345
2346 argcount = list_length(func->objargs);
2347 if (argcount > FUNC_MAX_ARGS)
2348 {
2349 if (objtype == OBJECT_PROCEDURE)
2350 ereport(ERROR,
2351 (errcode(ERRCODE_TOO_MANY_ARGUMENTS),
2352 errmsg_plural("procedures cannot have more than %d argument",
2353 "procedures cannot have more than %d arguments",
2355 FUNC_MAX_ARGS)));
2356 else
2357 ereport(ERROR,
2358 (errcode(ERRCODE_TOO_MANY_ARGUMENTS),
2359 errmsg_plural("functions cannot have more than %d argument",
2360 "functions cannot have more than %d arguments",
2362 FUNC_MAX_ARGS)));
2363 }
2364
2365 /*
2366 * First, perform a lookup considering only input arguments (traditional
2367 * Postgres rules).
2368 */
2369 i = 0;
2370 foreach(args_item, func->objargs)
2371 {
2372 TypeName *t = lfirst_node(TypeName, args_item);
2373
2374 argoids[i] = LookupTypeNameOid(NULL, t, missing_ok);
2375 if (!OidIsValid(argoids[i]))
2376 return InvalidOid; /* missing_ok must be true */
2377 i++;
2378 }
2379
2380 /*
2381 * Set nargs for LookupFuncNameInternal. It expects -1 to mean no args
2382 * were specified.
2383 */
2384 nargs = func->args_unspecified ? -1 : argcount;
2385
2386 /*
2387 * In args_unspecified mode, also tell LookupFuncNameInternal to consider
2388 * the object type, since there seems no reason not to. However, if we
2389 * have an argument list, disable the objtype check, because we'd rather
2390 * complain about "object is of wrong type" than "object doesn't exist".
2391 * (Note that with args, FuncnameGetCandidates will have ensured there's
2392 * only one argtype match, so we're not risking an ambiguity failure via
2393 * this choice.)
2394 */
2396 func->objname, nargs, argoids,
2397 false, missing_ok,
2398 &lookupError);
2399
2400 /*
2401 * If PROCEDURE or ROUTINE was specified, and we have an argument list
2402 * that contains no parameter mode markers, and we didn't already discover
2403 * that there's ambiguity, perform a lookup considering all arguments.
2404 * (Note: for a zero-argument procedure, or in args_unspecified mode, the
2405 * normal lookup is sufficient; so it's OK to require non-NIL objfuncargs
2406 * to perform this lookup.)
2407 */
2408 if ((objtype == OBJECT_PROCEDURE || objtype == OBJECT_ROUTINE) &&
2409 func->objfuncargs != NIL &&
2410 lookupError != FUNCLOOKUP_AMBIGUOUS)
2411 {
2412 bool have_param_mode = false;
2413
2414 /*
2415 * Check for non-default parameter mode markers. If there are any,
2416 * then the command does not conform to SQL-spec syntax, so we may
2417 * assume that the traditional Postgres lookup method of considering
2418 * only input parameters is sufficient. (Note that because the spec
2419 * doesn't have OUT arguments for functions, we also don't need this
2420 * hack in FUNCTION or AGGREGATE mode.)
2421 */
2422 foreach(args_item, func->objfuncargs)
2423 {
2425
2426 if (fp->mode != FUNC_PARAM_DEFAULT)
2427 {
2428 have_param_mode = true;
2429 break;
2430 }
2431 }
2432
2433 if (!have_param_mode)
2434 {
2435 Oid poid;
2436
2437 /* Without mode marks, objargs surely includes all params */
2438 Assert(list_length(func->objfuncargs) == argcount);
2439
2440 /* For objtype == OBJECT_PROCEDURE, we can ignore non-procedures */
2441 poid = LookupFuncNameInternal(objtype, func->objname,
2442 argcount, argoids,
2443 true, missing_ok,
2444 &lookupError);
2445
2446 /* Combine results, handling ambiguity */
2447 if (OidIsValid(poid))
2448 {
2449 if (OidIsValid(oid) && oid != poid)
2450 {
2451 /* oops, we got hits both ways, on different objects */
2452 oid = InvalidOid;
2453 lookupError = FUNCLOOKUP_AMBIGUOUS;
2454 }
2455 else
2456 oid = poid;
2457 }
2458 else if (lookupError == FUNCLOOKUP_AMBIGUOUS)
2459 oid = InvalidOid;
2460 }
2461 }
2462
2463 if (OidIsValid(oid))
2464 {
2465 /*
2466 * Even if we found the function, perform validation that the objtype
2467 * matches the prokind of the found function. For historical reasons
2468 * we allow the objtype of FUNCTION to include aggregates and window
2469 * functions; but we draw the line if the object is a procedure. That
2470 * is a new enough feature that this historical rule does not apply.
2471 *
2472 * (This check is partially redundant with the objtype check in
2473 * LookupFuncNameInternal; but not entirely, since we often don't tell
2474 * LookupFuncNameInternal to apply that check at all.)
2475 */
2476 switch (objtype)
2477 {
2478 case OBJECT_FUNCTION:
2479 /* Only complain if it's a procedure. */
2480 if (get_func_prokind(oid) == PROKIND_PROCEDURE)
2481 ereport(ERROR,
2482 (errcode(ERRCODE_WRONG_OBJECT_TYPE),
2483 errmsg("%s is not a function",
2484 func_signature_string(func->objname, argcount,
2485 NIL, argoids))));
2486 break;
2487
2488 case OBJECT_PROCEDURE:
2489 /* Reject if found object is not a procedure. */
2490 if (get_func_prokind(oid) != PROKIND_PROCEDURE)
2491 ereport(ERROR,
2492 (errcode(ERRCODE_WRONG_OBJECT_TYPE),
2493 errmsg("%s is not a procedure",
2494 func_signature_string(func->objname, argcount,
2495 NIL, argoids))));
2496 break;
2497
2498 case OBJECT_AGGREGATE:
2499 /* Reject if found object is not an aggregate. */
2500 if (get_func_prokind(oid) != PROKIND_AGGREGATE)
2501 ereport(ERROR,
2502 (errcode(ERRCODE_WRONG_OBJECT_TYPE),
2503 errmsg("function %s is not an aggregate",
2504 func_signature_string(func->objname, argcount,
2505 NIL, argoids))));
2506 break;
2507
2508 default:
2509 /* OBJECT_ROUTINE accepts anything. */
2510 break;
2511 }
2512
2513 return oid; /* All good */
2514 }
2515 else
2516 {
2517 /* Deal with cases where the lookup failed */
2518 switch (lookupError)
2519 {
2521 /* Suppress no-such-func errors when missing_ok is true */
2522 if (missing_ok)
2523 break;
2524
2525 switch (objtype)
2526 {
2527 case OBJECT_PROCEDURE:
2528 if (func->args_unspecified)
2529 ereport(ERROR,
2530 (errcode(ERRCODE_UNDEFINED_FUNCTION),
2531 errmsg("could not find a procedure named \"%s\"",
2532 NameListToString(func->objname))));
2533 else
2534 ereport(ERROR,
2535 (errcode(ERRCODE_UNDEFINED_FUNCTION),
2536 errmsg("procedure %s does not exist",
2537 func_signature_string(func->objname, argcount,
2538 NIL, argoids))));
2539 break;
2540
2541 case OBJECT_AGGREGATE:
2542 if (func->args_unspecified)
2543 ereport(ERROR,
2544 (errcode(ERRCODE_UNDEFINED_FUNCTION),
2545 errmsg("could not find an aggregate named \"%s\"",
2546 NameListToString(func->objname))));
2547 else if (argcount == 0)
2548 ereport(ERROR,
2549 (errcode(ERRCODE_UNDEFINED_FUNCTION),
2550 errmsg("aggregate %s(*) does not exist",
2551 NameListToString(func->objname))));
2552 else
2553 ereport(ERROR,
2554 (errcode(ERRCODE_UNDEFINED_FUNCTION),
2555 errmsg("aggregate %s does not exist",
2556 func_signature_string(func->objname, argcount,
2557 NIL, argoids))));
2558 break;
2559
2560 default:
2561 /* FUNCTION and ROUTINE */
2562 if (func->args_unspecified)
2563 ereport(ERROR,
2564 (errcode(ERRCODE_UNDEFINED_FUNCTION),
2565 errmsg("could not find a function named \"%s\"",
2566 NameListToString(func->objname))));
2567 else
2568 ereport(ERROR,
2569 (errcode(ERRCODE_UNDEFINED_FUNCTION),
2570 errmsg("function %s does not exist",
2571 func_signature_string(func->objname, argcount,
2572 NIL, argoids))));
2573 break;
2574 }
2575 break;
2576
2578 switch (objtype)
2579 {
2580 case OBJECT_FUNCTION:
2581 ereport(ERROR,
2582 (errcode(ERRCODE_AMBIGUOUS_FUNCTION),
2583 errmsg("function name \"%s\" is not unique",
2584 NameListToString(func->objname)),
2585 func->args_unspecified ?
2586 errhint("Specify the argument list to select the function unambiguously.") : 0));
2587 break;
2588 case OBJECT_PROCEDURE:
2589 ereport(ERROR,
2590 (errcode(ERRCODE_AMBIGUOUS_FUNCTION),
2591 errmsg("procedure name \"%s\" is not unique",
2592 NameListToString(func->objname)),
2593 func->args_unspecified ?
2594 errhint("Specify the argument list to select the procedure unambiguously.") : 0));
2595 break;
2596 case OBJECT_AGGREGATE:
2597 ereport(ERROR,
2598 (errcode(ERRCODE_AMBIGUOUS_FUNCTION),
2599 errmsg("aggregate name \"%s\" is not unique",
2600 NameListToString(func->objname)),
2601 func->args_unspecified ?
2602 errhint("Specify the argument list to select the aggregate unambiguously.") : 0));
2603 break;
2604 case OBJECT_ROUTINE:
2605 ereport(ERROR,
2606 (errcode(ERRCODE_AMBIGUOUS_FUNCTION),
2607 errmsg("routine name \"%s\" is not unique",
2608 NameListToString(func->objname)),
2609 func->args_unspecified ?
2610 errhint("Specify the argument list to select the routine unambiguously.") : 0));
2611 break;
2612
2613 default:
2614 Assert(false); /* Disallowed by Assert above */
2615 break;
2616 }
2617 break;
2618 }
2619
2620 return InvalidOid;
2621 }
2622}
char get_func_prokind(Oid funcid)
Definition: lsyscache.c:1985
Oid LookupTypeNameOid(ParseState *pstate, const TypeName *typeName, bool missing_ok)
Definition: parse_type.c:232
@ FUNC_PARAM_DEFAULT
Definition: parsenodes.h:3583
@ OBJECT_AGGREGATE
Definition: parsenodes.h:2326
@ OBJECT_ROUTINE
Definition: parsenodes.h:2359
@ OBJECT_PROCEDURE
Definition: parsenodes.h:2354
#define lfirst_node(type, lc)
Definition: pg_list.h:176
FunctionParameterMode mode
Definition: parsenodes.h:3591
List * objfuncargs
Definition: parsenodes.h:2613
List * objname
Definition: parsenodes.h:2611
List * objargs
Definition: parsenodes.h:2612
bool args_unspecified
Definition: parsenodes.h:2614

References ObjectWithArgs::args_unspecified, Assert(), ereport, errcode(), errhint(), errmsg(), errmsg_plural(), ERROR, FUNC_MAX_ARGS, FUNC_PARAM_DEFAULT, func_signature_string(), FUNCLOOKUP_AMBIGUOUS, FUNCLOOKUP_NOSUCHFUNC, get_func_prokind(), i, InvalidOid, lfirst_node, list_length(), LookupFuncNameInternal(), LookupTypeNameOid(), FunctionParameter::mode, NameListToString(), NIL, ObjectWithArgs::objargs, OBJECT_AGGREGATE, OBJECT_FUNCTION, OBJECT_PROCEDURE, OBJECT_ROUTINE, ObjectWithArgs::objfuncargs, ObjectWithArgs::objname, and OidIsValid.

Referenced by AlterFunction(), AlterOpFamilyAdd(), CreateCast(), CreateTransform(), DefineOpClass(), and get_object_address().

make_fn_arguments()

void make_fn_arguments ( ParseStatepstate,
Listfargs,
Oidactual_arg_types,
Oiddeclared_arg_types 
)

Definition at line 1948 of file parse_func.c.

1952{
1953 ListCell *current_fargs;
1954 int i = 0;
1955
1956 foreach(current_fargs, fargs)
1957 {
1958 /* types don't match? then force coercion using a function call... */
1959 if (actual_arg_types[i] != declared_arg_types[i])
1960 {
1961 Node *node = (Node *) lfirst(current_fargs);
1962
1963 /*
1964 * If arg is a NamedArgExpr, coerce its input expr instead --- we
1965 * want the NamedArgExpr to stay at the top level of the list.
1966 */
1967 if (IsA(node, NamedArgExpr))
1968 {
1969 NamedArgExpr *na = (NamedArgExpr *) node;
1970
1971 node = coerce_type(pstate,
1972 (Node *) na->arg,
1973 actual_arg_types[i],
1974 declared_arg_types[i], -1,
1977 -1);
1978 na->arg = (Expr *) node;
1979 }
1980 else
1981 {
1982 node = coerce_type(pstate,
1983 node,
1984 actual_arg_types[i],
1985 declared_arg_types[i], -1,
1988 -1);
1989 lfirst(current_fargs) = node;
1990 }
1991 }
1992 i++;
1993 }
1994}
Node * coerce_type(ParseState *pstate, Node *node, Oid inputTypeId, Oid targetTypeId, int32 targetTypeMod, CoercionContext ccontext, CoercionForm cformat, int location)
Definition: parse_coerce.c:157
@ COERCE_IMPLICIT_CAST
Definition: primnodes.h:768
Definition: primnodes.h:189
Expr * arg
Definition: primnodes.h:823

References NamedArgExpr::arg, COERCE_IMPLICIT_CAST, coerce_type(), COERCION_IMPLICIT, i, IsA, and lfirst.

Referenced by make_op(), make_scalar_array_op(), ParseFuncOrColumn(), and recheck_cast_function_args().

ParseFuncOrColumn()

Node * ParseFuncOrColumn ( ParseStatepstate,
Listfuncname,
Listfargs,
Nodelast_srf,
FuncCallfn,
bool  proc_call,
int  location 
)

Definition at line 92 of file parse_func.c.

94{
95 bool is_column = (fn == NULL);
96 List *agg_order = (fn ? fn->agg_order : NIL);
97 Expr *agg_filter = NULL;
98 WindowDef *over = (fn ? fn->over : NULL);
99 bool agg_within_group = (fn ? fn->agg_within_group : false);
100 bool agg_star = (fn ? fn->agg_star : false);
101 bool agg_distinct = (fn ? fn->agg_distinct : false);
102 bool func_variadic = (fn ? fn->func_variadic : false);
103 int ignore_nulls = (fn ? fn->ignore_nulls : NO_NULLTREATMENT);
104 CoercionForm funcformat = (fn ? fn->funcformat : COERCE_EXPLICIT_CALL);
105 bool could_be_projection;
106 Oid rettype;
107 Oid funcid;
108 ListCell *l;
109 Node *first_arg = NULL;
110 int nargs;
111 int nargsplusdefs;
112 Oid actual_arg_types[FUNC_MAX_ARGS];
113 Oid *declared_arg_types;
114 List *argnames;
115 List *argdefaults;
116 Node *retval;
117 bool retset;
118 int nvargs;
119 Oid vatype;
120 FuncDetailCode fdresult;
121 int fgc_flags;
122 char aggkind = 0;
123 ParseCallbackState pcbstate;
124
125 /*
126 * If there's an aggregate filter, transform it using transformWhereClause
127 */
128 if (fn && fn->agg_filter != NULL)
129 agg_filter = (Expr *) transformWhereClause(pstate, fn->agg_filter,
131 "FILTER");
132
133 /*
134 * Most of the rest of the parser just assumes that functions do not have
135 * more than FUNC_MAX_ARGS parameters. We have to test here to protect
136 * against array overruns, etc. Of course, this may not be a function,
137 * but the test doesn't hurt.
138 */
139 if (list_length(fargs) > FUNC_MAX_ARGS)
141 (errcode(ERRCODE_TOO_MANY_ARGUMENTS),
142 errmsg_plural("cannot pass more than %d argument to a function",
143 "cannot pass more than %d arguments to a function",
146 parser_errposition(pstate, location)));
147
148 /*
149 * Extract arg type info in preparation for function lookup.
150 *
151 * If any arguments are Param markers of type VOID, we discard them from
152 * the parameter list. This is a hack to allow the JDBC driver to not have
153 * to distinguish "input" and "output" parameter symbols while parsing
154 * function-call constructs. Don't do this if dealing with column syntax,
155 * nor if we had WITHIN GROUP (because in that case it's critical to keep
156 * the argument count unchanged).
157 */
158 nargs = 0;
159 foreach(l, fargs)
160 {
161 Node *arg = lfirst(l);
162 Oid argtype = exprType(arg);
163
164 if (argtype == VOIDOID && IsA(arg, Param) &&
165 !is_column && !agg_within_group)
166 {
167 fargs = foreach_delete_current(fargs, l);
168 continue;
169 }
170
171 actual_arg_types[nargs++] = argtype;
172 }
173
174 /*
175 * Check for named arguments; if there are any, build a list of names.
176 *
177 * We allow mixed notation (some named and some not), but only with all
178 * the named parameters after all the unnamed ones. So the name list
179 * corresponds to the last N actual parameters and we don't need any extra
180 * bookkeeping to match things up.
181 */
182 argnames = NIL;
183 foreach(l, fargs)
184 {
185 Node *arg = lfirst(l);
186
187 if (IsA(arg, NamedArgExpr))
188 {
189 NamedArgExpr *na = (NamedArgExpr *) arg;
190 ListCell *lc;
191
192 /* Reject duplicate arg names */
193 foreach(lc, argnames)
194 {
195 if (strcmp(na->name, (char *) lfirst(lc)) == 0)
197 (errcode(ERRCODE_SYNTAX_ERROR),
198 errmsg("argument name \"%s\" used more than once",
199 na->name),
200 parser_errposition(pstate, na->location)));
201 }
202 argnames = lappend(argnames, na->name);
203 }
204 else
205 {
206 if (argnames != NIL)
208 (errcode(ERRCODE_SYNTAX_ERROR),
209 errmsg("positional argument cannot follow named argument"),
211 }
212 }
213
214 if (fargs)
215 {
216 first_arg = linitial(fargs);
217 Assert(first_arg != NULL);
218 }
219
220 /*
221 * Decide whether it's legitimate to consider the construct to be a column
222 * projection. For that, there has to be a single argument of complex
223 * type, the function name must not be qualified, and there cannot be any
224 * syntactic decoration that'd require it to be a function (such as
225 * aggregate or variadic decoration, or named arguments).
226 */
227 could_be_projection = (nargs == 1 && !proc_call &&
228 agg_order == NIL && agg_filter == NULL &&
229 !agg_star && !agg_distinct && over == NULL &&
230 !func_variadic && argnames == NIL &&
231 list_length(funcname) == 1 &&
232 (actual_arg_types[0] == RECORDOID ||
233 ISCOMPLEX(actual_arg_types[0])));
234
235 /*
236 * If it's column syntax, check for column projection case first.
237 */
238 if (could_be_projection && is_column)
239 {
240 retval = ParseComplexProjection(pstate,
242 first_arg,
243 location);
244 if (retval)
245 return retval;
246
247 /*
248 * If ParseComplexProjection doesn't recognize it as a projection,
249 * just press on.
250 */
251 }
252
253 /*
254 * func_get_detail looks up the function in the catalogs, does
255 * disambiguation for polymorphic functions, handles inheritance, and
256 * returns the funcid and type and set or singleton status of the
257 * function's return value. It also returns the true argument types to
258 * the function.
259 *
260 * Note: for a named-notation or variadic function call, the reported
261 * "true" types aren't really what is in pg_proc: the types are reordered
262 * to match the given argument order of named arguments, and a variadic
263 * argument is replaced by a suitable number of copies of its element
264 * type. We'll fix up the variadic case below. We may also have to deal
265 * with default arguments.
266 */
267
268 setup_parser_errposition_callback(&pcbstate, pstate, location);
269
270 fdresult = func_get_detail(funcname, fargs, argnames, nargs,
271 actual_arg_types,
272 !func_variadic, true, proc_call,
273 &fgc_flags,
274 &funcid, &rettype, &retset,
275 &nvargs, &vatype,
276 &declared_arg_types, &argdefaults);
277
279
280 /*
281 * Check for various wrong-kind-of-routine cases.
282 */
283
284 /* If this is a CALL, reject things that aren't procedures */
285 if (proc_call &&
286 (fdresult == FUNCDETAIL_NORMAL ||
287 fdresult == FUNCDETAIL_AGGREGATE ||
288 fdresult == FUNCDETAIL_WINDOWFUNC ||
289 fdresult == FUNCDETAIL_COERCION))
291 (errcode(ERRCODE_WRONG_OBJECT_TYPE),
292 errmsg("%s is not a procedure",
294 argnames,
295 actual_arg_types)),
296 errhint("To call a function, use SELECT."),
297 parser_errposition(pstate, location)));
298 /* Conversely, if not a CALL, reject procedures */
299 if (fdresult == FUNCDETAIL_PROCEDURE && !proc_call)
301 (errcode(ERRCODE_WRONG_OBJECT_TYPE),
302 errmsg("%s is a procedure",
304 argnames,
305 actual_arg_types)),
306 errhint("To call a procedure, use CALL."),
307 parser_errposition(pstate, location)));
308
309 if (fdresult == FUNCDETAIL_NORMAL ||
310 fdresult == FUNCDETAIL_PROCEDURE ||
311 fdresult == FUNCDETAIL_COERCION)
312 {
313 /*
314 * In these cases, complain if there was anything indicating it must
315 * be an aggregate or window function.
316 */
317 if (agg_star)
319 (errcode(ERRCODE_WRONG_OBJECT_TYPE),
320 errmsg("%s(*) specified, but %s is not an aggregate function",
323 parser_errposition(pstate, location)));
324 if (agg_distinct)
326 (errcode(ERRCODE_WRONG_OBJECT_TYPE),
327 errmsg("DISTINCT specified, but %s is not an aggregate function",
329 parser_errposition(pstate, location)));
330 if (agg_within_group)
332 (errcode(ERRCODE_WRONG_OBJECT_TYPE),
333 errmsg("WITHIN GROUP specified, but %s is not an aggregate function",
335 parser_errposition(pstate, location)));
336 if (agg_order != NIL)
338 (errcode(ERRCODE_WRONG_OBJECT_TYPE),
339 errmsg("ORDER BY specified, but %s is not an aggregate function",
341 parser_errposition(pstate, location)));
342 if (agg_filter)
344 (errcode(ERRCODE_WRONG_OBJECT_TYPE),
345 errmsg("FILTER specified, but %s is not an aggregate function",
347 parser_errposition(pstate, location)));
348 if (over)
350 (errcode(ERRCODE_WRONG_OBJECT_TYPE),
351 errmsg("OVER specified, but %s is not a window function nor an aggregate function",
353 parser_errposition(pstate, location)));
354 }
355
356 /*
357 * So far so good, so do some fdresult-type-specific processing.
358 */
359 if (fdresult == FUNCDETAIL_NORMAL || fdresult == FUNCDETAIL_PROCEDURE)
360 {
361 /* Nothing special to do for these cases. */
362 }
363 else if (fdresult == FUNCDETAIL_AGGREGATE)
364 {
365 /*
366 * It's an aggregate; fetch needed info from the pg_aggregate entry.
367 */
368 HeapTuple tup;
369 Form_pg_aggregate classForm;
370 int catDirectArgs;
371
372 tup = SearchSysCache1(AGGFNOID, ObjectIdGetDatum(funcid));
373 if (!HeapTupleIsValid(tup)) /* should not happen */
374 elog(ERROR, "cache lookup failed for aggregate %u", funcid);
375 classForm = (Form_pg_aggregate) GETSTRUCT(tup);
376 aggkind = classForm->aggkind;
377 catDirectArgs = classForm->aggnumdirectargs;
378 ReleaseSysCache(tup);
379
380 /* Now check various disallowed cases. */
381 if (AGGKIND_IS_ORDERED_SET(aggkind))
382 {
383 int numAggregatedArgs;
384 int numDirectArgs;
385
386 if (!agg_within_group)
388 (errcode(ERRCODE_WRONG_OBJECT_TYPE),
389 errmsg("WITHIN GROUP is required for ordered-set aggregate %s",
391 parser_errposition(pstate, location)));
392 if (over)
394 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
395 errmsg("OVER is not supported for ordered-set aggregate %s",
397 parser_errposition(pstate, location)));
398 /* gram.y rejects DISTINCT + WITHIN GROUP */
399 Assert(!agg_distinct);
400 /* gram.y rejects VARIADIC + WITHIN GROUP */
401 Assert(!func_variadic);
402
403 /*
404 * Since func_get_detail was working with an undifferentiated list
405 * of arguments, it might have selected an aggregate that doesn't
406 * really match because it requires a different division of direct
407 * and aggregated arguments. Check that the number of direct
408 * arguments is actually OK; if not, throw an "undefined function"
409 * error, similarly to the case where a misplaced ORDER BY is used
410 * in a regular aggregate call.
411 */
412 numAggregatedArgs = list_length(agg_order);
413 numDirectArgs = nargs - numAggregatedArgs;
414 Assert(numDirectArgs >= 0);
415
416 if (!OidIsValid(vatype))
417 {
418 /* Test is simple if aggregate isn't variadic */
419 if (numDirectArgs != catDirectArgs)
421 (errcode(ERRCODE_UNDEFINED_FUNCTION),
422 errmsg("function %s does not exist",
424 argnames,
425 actual_arg_types)),
426 errhint_plural("There is an ordered-set aggregate %s, but it requires %d direct argument, not %d.",
427 "There is an ordered-set aggregate %s, but it requires %d direct arguments, not %d.",
428 catDirectArgs,
430 catDirectArgs, numDirectArgs),
431 parser_errposition(pstate, location)));
432 }
433 else
434 {
435 /*
436 * If it's variadic, we have two cases depending on whether
437 * the agg was "... ORDER BY VARIADIC" or "..., VARIADIC ORDER
438 * BY VARIADIC". It's the latter if catDirectArgs equals
439 * pronargs; to save a catalog lookup, we reverse-engineer
440 * pronargs from the info we got from func_get_detail.
441 */
442 int pronargs;
443
444 pronargs = nargs;
445 if (nvargs > 1)
446 pronargs -= nvargs - 1;
447 if (catDirectArgs < pronargs)
448 {
449 /* VARIADIC isn't part of direct args, so still easy */
450 if (numDirectArgs != catDirectArgs)
452 (errcode(ERRCODE_UNDEFINED_FUNCTION),
453 errmsg("function %s does not exist",
455 argnames,
456 actual_arg_types)),
457 errhint_plural("There is an ordered-set aggregate %s, but it requires %d direct argument, not %d.",
458 "There is an ordered-set aggregate %s, but it requires %d direct arguments, not %d.",
459 catDirectArgs,
461 catDirectArgs, numDirectArgs),
462 parser_errposition(pstate, location)));
463 }
464 else
465 {
466 /*
467 * Both direct and aggregated args were declared variadic.
468 * For a standard ordered-set aggregate, it's okay as long
469 * as there aren't too few direct args. For a
470 * hypothetical-set aggregate, we assume that the
471 * hypothetical arguments are those that matched the
472 * variadic parameter; there must be just as many of them
473 * as there are aggregated arguments.
474 */
475 if (aggkind == AGGKIND_HYPOTHETICAL)
476 {
477 if (nvargs != 2 * numAggregatedArgs)
479 (errcode(ERRCODE_UNDEFINED_FUNCTION),
480 errmsg("function %s does not exist",
482 argnames,
483 actual_arg_types)),
484 errhint("To use the hypothetical-set aggregate %s, the number of hypothetical direct arguments (here %d) must match the number of ordering columns (here %d).",
486 nvargs - numAggregatedArgs, numAggregatedArgs),
487 parser_errposition(pstate, location)));
488 }
489 else
490 {
491 if (nvargs <= numAggregatedArgs)
493 (errcode(ERRCODE_UNDEFINED_FUNCTION),
494 errmsg("function %s does not exist",
496 argnames,
497 actual_arg_types)),
498 errhint_plural("There is an ordered-set aggregate %s, but it requires at least %d direct argument.",
499 "There is an ordered-set aggregate %s, but it requires at least %d direct arguments.",
500 catDirectArgs,
502 catDirectArgs),
503 parser_errposition(pstate, location)));
504 }
505 }
506 }
507
508 /* Check type matching of hypothetical arguments */
509 if (aggkind == AGGKIND_HYPOTHETICAL)
510 unify_hypothetical_args(pstate, fargs, numAggregatedArgs,
511 actual_arg_types, declared_arg_types);
512 }
513 else
514 {
515 /* Normal aggregate, so it can't have WITHIN GROUP */
516 if (agg_within_group)
518 (errcode(ERRCODE_WRONG_OBJECT_TYPE),
519 errmsg("%s is not an ordered-set aggregate, so it cannot have WITHIN GROUP",
521 parser_errposition(pstate, location)));
522
523 /* It also can't treat nulls as a window function */
524 if (ignore_nulls != NO_NULLTREATMENT)
526 (errcode(ERRCODE_WRONG_OBJECT_TYPE),
527 errmsg("aggregate functions do not accept RESPECT/IGNORE NULLS"),
528 parser_errposition(pstate, location)));
529 }
530 }
531 else if (fdresult == FUNCDETAIL_WINDOWFUNC)
532 {
533 /*
534 * True window functions must be called with a window definition.
535 */
536 if (!over)
538 (errcode(ERRCODE_WRONG_OBJECT_TYPE),
539 errmsg("window function %s requires an OVER clause",
541 parser_errposition(pstate, location)));
542 /* And, per spec, WITHIN GROUP isn't allowed */
543 if (agg_within_group)
545 (errcode(ERRCODE_WRONG_OBJECT_TYPE),
546 errmsg("window function %s cannot have WITHIN GROUP",
548 parser_errposition(pstate, location)));
549 }
550 else if (fdresult == FUNCDETAIL_COERCION)
551 {
552 /*
553 * We interpreted it as a type coercion. coerce_type can handle these
554 * cases, so why duplicate code...
555 */
556 return coerce_type(pstate, linitial(fargs),
557 actual_arg_types[0], rettype, -1,
559 }
560 else if (fdresult == FUNCDETAIL_MULTIPLE)
561 {
562 /*
563 * We found multiple possible functional matches. If we are dealing
564 * with attribute notation, return failure, letting the caller report
565 * "no such column" (we already determined there wasn't one). If
566 * dealing with function notation, report "ambiguous function",
567 * regardless of whether there's also a column by this name.
568 */
569 if (is_column)
570 return NULL;
571
572 if (proc_call)
574 (errcode(ERRCODE_AMBIGUOUS_FUNCTION),
575 errmsg("procedure %s is not unique",
576 func_signature_string(funcname, nargs, argnames,
577 actual_arg_types)),
578 errdetail("Could not choose a best candidate procedure."),
579 errhint("You might need to add explicit type casts."),
580 parser_errposition(pstate, location)));
581 else
583 (errcode(ERRCODE_AMBIGUOUS_FUNCTION),
584 errmsg("function %s is not unique",
585 func_signature_string(funcname, nargs, argnames,
586 actual_arg_types)),
587 errdetail("Could not choose a best candidate function."),
588 errhint("You might need to add explicit type casts."),
589 parser_errposition(pstate, location)));
590 }
591 else
592 {
593 /*
594 * Not found as a function. If we are dealing with attribute
595 * notation, return failure, letting the caller report "no such
596 * column" (we already determined there wasn't one).
597 */
598 if (is_column)
599 return NULL;
600
601 /*
602 * Check for column projection interpretation, since we didn't before.
603 */
604 if (could_be_projection)
605 {
606 retval = ParseComplexProjection(pstate,
608 first_arg,
609 location);
610 if (retval)
611 return retval;
612 }
613
614 /*
615 * No function, and no column either. Since we're dealing with
616 * function notation, report "function/procedure does not exist".
617 * Depending on what was returned in fgc_flags, we can add some color
618 * to that with detail or hint messages.
619 */
620 if (list_length(agg_order) > 1 && !agg_within_group)
621 {
622 /* It's agg(x, ORDER BY y,z) ... perhaps misplaced ORDER BY */
624 (errcode(ERRCODE_UNDEFINED_FUNCTION),
625 errmsg("function %s does not exist",
626 func_signature_string(funcname, nargs, argnames,
627 actual_arg_types)),
628 errdetail("No aggregate function matches the given name and argument types."),
629 errhint("Perhaps you misplaced ORDER BY; ORDER BY must appear "
630 "after all regular arguments of the aggregate."),
631 parser_errposition(pstate, location)));
632 }
633 else if (proc_call)
635 (errcode(ERRCODE_UNDEFINED_FUNCTION),
636 errmsg("procedure %s does not exist",
637 func_signature_string(funcname, nargs, argnames,
638 actual_arg_types)),
639 func_lookup_failure_details(fgc_flags, argnames,
640 proc_call),
641 parser_errposition(pstate, location)));
642 else
644 (errcode(ERRCODE_UNDEFINED_FUNCTION),
645 errmsg("function %s does not exist",
646 func_signature_string(funcname, nargs, argnames,
647 actual_arg_types)),
648 func_lookup_failure_details(fgc_flags, argnames,
649 proc_call),
650 parser_errposition(pstate, location)));
651 }
652
653 /*
654 * If there are default arguments, we have to include their types in
655 * actual_arg_types for the purpose of checking generic type consistency.
656 * However, we do NOT put them into the generated parse node, because
657 * their actual values might change before the query gets run. The
658 * planner has to insert the up-to-date values at plan time.
659 */
660 nargsplusdefs = nargs;
661 foreach(l, argdefaults)
662 {
663 Node *expr = (Node *) lfirst(l);
664
665 /* probably shouldn't happen ... */
666 if (nargsplusdefs >= FUNC_MAX_ARGS)
668 (errcode(ERRCODE_TOO_MANY_ARGUMENTS),
669 errmsg_plural("cannot pass more than %d argument to a function",
670 "cannot pass more than %d arguments to a function",
673 parser_errposition(pstate, location)));
674
675 actual_arg_types[nargsplusdefs++] = exprType(expr);
676 }
677
678 /*
679 * enforce consistency with polymorphic argument and return types,
680 * possibly adjusting return type or declared_arg_types (which will be
681 * used as the cast destination by make_fn_arguments)
682 */
683 rettype = enforce_generic_type_consistency(actual_arg_types,
684 declared_arg_types,
685 nargsplusdefs,
686 rettype,
687 false);
688
689 /* perform the necessary typecasting of arguments */
690 make_fn_arguments(pstate, fargs, actual_arg_types, declared_arg_types);
691
692 /*
693 * If the function isn't actually variadic, forget any VARIADIC decoration
694 * on the call. (Perhaps we should throw an error instead, but
695 * historically we've allowed people to write that.)
696 */
697 if (!OidIsValid(vatype))
698 {
699 Assert(nvargs == 0);
700 func_variadic = false;
701 }
702
703 /*
704 * If it's a variadic function call, transform the last nvargs arguments
705 * into an array --- unless it's an "any" variadic.
706 */
707 if (nvargs > 0 && vatype != ANYOID)
708 {
710 int non_var_args = nargs - nvargs;
711 List *vargs;
712
713 Assert(non_var_args >= 0);
714 vargs = list_copy_tail(fargs, non_var_args);
715 fargs = list_truncate(fargs, non_var_args);
716
717 newa->elements = vargs;
718 /* assume all the variadic arguments were coerced to the same type */
719 newa->element_typeid = exprType((Node *) linitial(vargs));
720 newa->array_typeid = get_array_type(newa->element_typeid);
721 if (!OidIsValid(newa->array_typeid))
723 (errcode(ERRCODE_UNDEFINED_OBJECT),
724 errmsg("could not find array type for data type %s",
725 format_type_be(newa->element_typeid)),
726 parser_errposition(pstate, exprLocation((Node *) vargs))));
727 /* array_collid will be set by parse_collate.c */
728 newa->multidims = false;
729 newa->location = exprLocation((Node *) vargs);
730
731 fargs = lappend(fargs, newa);
732
733 /* We could not have had VARIADIC marking before ... */
734 Assert(!func_variadic);
735 /* ... but now, it's a VARIADIC call */
736 func_variadic = true;
737 }
738
739 /*
740 * If an "any" variadic is called with explicit VARIADIC marking, insist
741 * that the variadic parameter be of some array type.
742 */
743 if (nargs > 0 && vatype == ANYOID && func_variadic)
744 {
745 Oid va_arr_typid = actual_arg_types[nargs - 1];
746
747 if (!OidIsValid(get_base_element_type(va_arr_typid)))
749 (errcode(ERRCODE_DATATYPE_MISMATCH),
750 errmsg("VARIADIC argument must be an array"),
751 parser_errposition(pstate,
752 exprLocation((Node *) llast(fargs)))));
753 }
754
755 /* if it returns a set, check that's OK */
756 if (retset)
757 check_srf_call_placement(pstate, last_srf, location);
758
759 /* build the appropriate output structure */
760 if (fdresult == FUNCDETAIL_NORMAL || fdresult == FUNCDETAIL_PROCEDURE)
761 {
762 FuncExpr *funcexpr = makeNode(FuncExpr);
763
764 funcexpr->funcid = funcid;
765 funcexpr->funcresulttype = rettype;
766 funcexpr->funcretset = retset;
767 funcexpr->funcvariadic = func_variadic;
768 funcexpr->funcformat = funcformat;
769 /* funccollid and inputcollid will be set by parse_collate.c */
770 funcexpr->args = fargs;
771 funcexpr->location = location;
772
773 retval = (Node *) funcexpr;
774 }
775 else if (fdresult == FUNCDETAIL_AGGREGATE && !over)
776 {
777 /* aggregate function */
778 Aggref *aggref = makeNode(Aggref);
779
780 aggref->aggfnoid = funcid;
781 aggref->aggtype = rettype;
782 /* aggcollid and inputcollid will be set by parse_collate.c */
783 aggref->aggtranstype = InvalidOid; /* will be set by planner */
784 /* aggargtypes will be set by transformAggregateCall */
785 /* aggdirectargs and args will be set by transformAggregateCall */
786 /* aggorder and aggdistinct will be set by transformAggregateCall */
787 aggref->aggfilter = agg_filter;
788 aggref->aggstar = agg_star;
789 aggref->aggvariadic = func_variadic;
790 aggref->aggkind = aggkind;
791 aggref->aggpresorted = false;
792 /* agglevelsup will be set by transformAggregateCall */
793 aggref->aggsplit = AGGSPLIT_SIMPLE; /* planner might change this */
794 aggref->aggno = -1; /* planner will set aggno and aggtransno */
795 aggref->aggtransno = -1;
796 aggref->location = location;
797
798 /*
799 * Reject attempt to call a parameterless aggregate without (*)
800 * syntax. This is mere pedantry but some folks insisted ...
801 */
802 if (fargs == NIL && !agg_star && !agg_within_group)
804 (errcode(ERRCODE_WRONG_OBJECT_TYPE),
805 errmsg("%s(*) must be used to call a parameterless aggregate function",
807 parser_errposition(pstate, location)));
808
809 if (retset)
811 (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
812 errmsg("aggregates cannot return sets"),
813 parser_errposition(pstate, location)));
814
815 /*
816 * We might want to support named arguments later, but disallow it for
817 * now. We'd need to figure out the parsed representation (should the
818 * NamedArgExprs go above or below the TargetEntry nodes?) and then
819 * teach the planner to reorder the list properly. Or maybe we could
820 * make transformAggregateCall do that? However, if you'd also like
821 * to allow default arguments for aggregates, we'd need to do it in
822 * planning to avoid semantic problems.
823 */
824 if (argnames != NIL)
826 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
827 errmsg("aggregates cannot use named arguments"),
828 parser_errposition(pstate, location)));
829
830 /* parse_agg.c does additional aggregate-specific processing */
831 transformAggregateCall(pstate, aggref, fargs, agg_order, agg_distinct);
832
833 retval = (Node *) aggref;
834 }
835 else
836 {
837 /* window function */
839
840 Assert(over); /* lack of this was checked above */
841 Assert(!agg_within_group); /* also checked above */
842
843 wfunc->winfnoid = funcid;
844 wfunc->wintype = rettype;
845 /* wincollid and inputcollid will be set by parse_collate.c */
846 wfunc->args = fargs;
847 /* winref will be set by transformWindowFuncCall */
848 wfunc->winstar = agg_star;
849 wfunc->winagg = (fdresult == FUNCDETAIL_AGGREGATE);
850 wfunc->aggfilter = agg_filter;
851 wfunc->ignore_nulls = ignore_nulls;
852 wfunc->runCondition = NIL;
853 wfunc->location = location;
854
855 /*
856 * agg_star is allowed for aggregate functions but distinct isn't
857 */
858 if (agg_distinct)
860 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
861 errmsg("DISTINCT is not implemented for window functions"),
862 parser_errposition(pstate, location)));
863
864 /*
865 * Reject attempt to call a parameterless aggregate without (*)
866 * syntax. This is mere pedantry but some folks insisted ...
867 */
868 if (wfunc->winagg && fargs == NIL && !agg_star)
870 (errcode(ERRCODE_WRONG_OBJECT_TYPE),
871 errmsg("%s(*) must be used to call a parameterless aggregate function",
873 parser_errposition(pstate, location)));
874
875 /*
876 * ordered aggs not allowed in windows yet
877 */
878 if (agg_order != NIL)
880 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
881 errmsg("aggregate ORDER BY is not implemented for window functions"),
882 parser_errposition(pstate, location)));
883
884 /*
885 * FILTER is not yet supported with true window functions
886 */
887 if (!wfunc->winagg && agg_filter)
889 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
890 errmsg("FILTER is not implemented for non-aggregate window functions"),
891 parser_errposition(pstate, location)));
892
893 /*
894 * Window functions can't either take or return sets
895 */
896 if (pstate->p_last_srf != last_srf)
898 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
899 errmsg("window function calls cannot contain set-returning function calls"),
900 errhint("You might be able to move the set-returning function into a LATERAL FROM item."),
901 parser_errposition(pstate,
902 exprLocation(pstate->p_last_srf))));
903
904 if (retset)
906 (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
907 errmsg("window functions cannot return sets"),
908 parser_errposition(pstate, location)));
909
910 /* parse_agg.c does additional window-func-specific processing */
911 transformWindowFuncCall(pstate, wfunc, over);
912
913 retval = (Node *) wfunc;
914 }
915
916 /* if it returns a set, remember it for error checks at higher levels */
917 if (retset)
918 pstate->p_last_srf = retval;
919
920 return retval;
921}
int errdetail(const char *fmt,...)
Definition: elog.c:1207
int errhint_plural(const char *fmt_singular, const char *fmt_plural, unsigned long n,...)
Definition: elog.c:1364
List * list_copy_tail(const List *oldlist, int nskip)
Definition: list.c:1613
List * list_truncate(List *list, int new_size)
Definition: list.c:631
Oid get_base_element_type(Oid typid)
Definition: lsyscache.c:2999
Oid get_array_type(Oid typid)
Definition: lsyscache.c:2954
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:42
@ AGGSPLIT_SIMPLE
Definition: nodes.h:387
#define makeNode(_type_)
Definition: nodes.h:161
void transformWindowFuncCall(ParseState *pstate, WindowFunc *wfunc, WindowDef *windef)
Definition: parse_agg.c:851
void transformAggregateCall(ParseState *pstate, Aggref *agg, List *args, List *aggorder, bool agg_distinct)
Definition: parse_agg.c:109
Node * transformWhereClause(ParseState *pstate, Node *clause, ParseExprKind exprKind, const char *constructName)
Definition: parse_clause.c:1854
Oid enforce_generic_type_consistency(const Oid *actual_arg_types, Oid *declared_arg_types, int nargs, Oid rettype, bool allow_poly)
Definition: parse_coerce.c:2131
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)
Definition: parse_func.c:1513
static Node * ParseComplexProjection(ParseState *pstate, const char *funcname, Node *first_arg, int location)
Definition: parse_func.c:2035
void make_fn_arguments(ParseState *pstate, List *fargs, Oid *actual_arg_types, Oid *declared_arg_types)
Definition: parse_func.c:1948
static void unify_hypothetical_args(ParseState *pstate, List *fargs, int numAggregatedArgs, Oid *actual_arg_types, Oid *declared_arg_types)
Definition: parse_func.c:1864
void check_srf_call_placement(ParseState *pstate, Node *last_srf, int location)
Definition: parse_func.c:2636
static int func_lookup_failure_details(int fgc_flags, List *argnames, bool proc_call)
Definition: parse_func.c:930
void cancel_parser_errposition_callback(ParseCallbackState *pcbstate)
Definition: parse_node.c:156
void setup_parser_errposition_callback(ParseCallbackState *pcbstate, ParseState *pstate, int location)
Definition: parse_node.c:140
FormData_pg_aggregate * Form_pg_aggregate
Definition: pg_aggregate.h:109
void * arg
#define llast(l)
Definition: pg_list.h:198
#define foreach_delete_current(lst, var_or_cell)
Definition: pg_list.h:391
int16 pronargs
Definition: pg_proc.h:81
CoercionForm
Definition: primnodes.h:765
@ COERCE_EXPLICIT_CALL
Definition: primnodes.h:766
#define NO_NULLTREATMENT
Definition: primnodes.h:588
Definition: primnodes.h:459
Oid aggfnoid
Definition: primnodes.h:463
Expr * aggfilter
Definition: primnodes.h:496
ParseLoc location
Definition: primnodes.h:526
ParseLoc location
Definition: primnodes.h:1420
ParseLoc location
Definition: primnodes.h:802
Oid funcid
Definition: primnodes.h:782
List * args
Definition: primnodes.h:800
ParseLoc location
Definition: primnodes.h:829
Definition: primnodes.h:391
List * args
Definition: primnodes.h:605
Expr * aggfilter
Definition: primnodes.h:607
ParseLoc location
Definition: primnodes.h:619
int ignore_nulls
Definition: primnodes.h:617
Oid winfnoid
Definition: primnodes.h:597
static void * fn(void *arg)
Definition: thread-alloc.c:119
#define strVal(v)
Definition: value.h:82

References Aggref::aggfilter, WindowFunc::aggfilter, Aggref::aggfnoid, AGGSPLIT_SIMPLE, arg, WindowFunc::args, FuncExpr::args, Assert(), cancel_parser_errposition_callback(), check_srf_call_placement(), COERCE_EXPLICIT_CALL, coerce_type(), COERCION_EXPLICIT, elog, enforce_generic_type_consistency(), ereport, errcode(), errdetail(), errhint(), errhint_plural(), errmsg(), errmsg_plural(), ERROR, EXPR_KIND_FILTER, exprLocation(), exprType(), fn(), foreach_delete_current, format_type_be(), func_get_detail(), func_lookup_failure_details(), FUNC_MAX_ARGS, func_signature_string(), FUNCDETAIL_AGGREGATE, FUNCDETAIL_COERCION, FUNCDETAIL_MULTIPLE, FUNCDETAIL_NORMAL, FUNCDETAIL_PROCEDURE, FUNCDETAIL_WINDOWFUNC, FuncExpr::funcid, funcname, get_array_type(), get_base_element_type(), GETSTRUCT(), HeapTupleIsValid, WindowFunc::ignore_nulls, InvalidOid, IsA, ISCOMPLEX, lappend(), lfirst, linitial, list_copy_tail(), list_length(), list_truncate(), llast, Aggref::location, WindowFunc::location, FuncExpr::location, NamedArgExpr::location, ArrayExpr::location, make_fn_arguments(), makeNode, NameListToString(), NIL, NO_NULLTREATMENT, ObjectIdGetDatum(), OidIsValid, ParseState::p_last_srf, ParseComplexProjection(), parser_errposition(), pronargs, ReleaseSysCache(), SearchSysCache1(), setup_parser_errposition_callback(), strVal, transformAggregateCall(), transformWhereClause(), transformWindowFuncCall(), unify_hypothetical_args(), and WindowFunc::winfnoid.

Referenced by sql_fn_post_column_ref(), transformCallStmt(), transformColumnRef(), transformFuncCall(), and transformIndirection().

AltStyle によって変換されたページ (->オリジナル) /