* Add an entry for a function (or functions) to the pstate's range table * (p_rtable). Then, construct and return a ParseNamespaceItem for the new RTE. * * This is much like addRangeTableEntry() except that it makes a function RTE. */
| 1742 | * This is much like addRangeTableEntry() except that it makes a function RTE. |
| 1743 | */ |
| 1744 | ParseNamespaceItem * |
| 1745 | addRangeTableEntryForFunction(ParseState *pstate, |
| 1746 | List *funcnames, |
| 1747 | List *funcexprs, |
| 1748 | List *coldeflists, |
| 1749 | RangeFunction *rangefunc, |
| 1750 | bool lateral, |
| 1751 | bool inFromCl) |
| 1752 | { |
| 1753 | RangeTblEntry *rte = makeNode(RangeTblEntry); |
| 1754 | Oid funcDescribe = InvalidOid; |
| 1755 | Alias *alias = rangefunc->alias; |
| 1756 | Alias *eref; |
| 1757 | char *aliasname; |
| 1758 | int nfuncs = list_length(funcexprs); |
| 1759 | TupleDesc *functupdescs; |
| 1760 | TupleDesc tupdesc; |
| 1761 | ListCell *lc1, |
| 1762 | *lc2, |
| 1763 | *lc3; |
| 1764 | int i; |
| 1765 | int j; |
| 1766 | int funcno; |
| 1767 | int natts, |
| 1768 | totalatts; |
| 1769 | |
| 1770 | Assert(pstate != NULL); |
| 1771 | |
| 1772 | rte->rtekind = RTE_FUNCTION; |
| 1773 | rte->relid = InvalidOid; |
| 1774 | rte->subquery = NULL; |
| 1775 | rte->functions = NIL; /* we'll fill this list below */ |
| 1776 | rte->funcordinality = rangefunc->ordinality; |
| 1777 | rte->alias = alias; |
| 1778 | |
| 1779 | /* |
| 1780 | * Choose the RTE alias name. We default to using the first function's |
| 1781 | * name even when there's more than one; which is maybe arguable but beats |
| 1782 | * using something constant like "table". |
| 1783 | */ |
| 1784 | if (alias) |
| 1785 | aliasname = alias->aliasname; |
| 1786 | else |
| 1787 | aliasname = linitial(funcnames); |
| 1788 | |
| 1789 | eref = makeAlias(aliasname, NIL); |
| 1790 | rte->eref = eref; |
| 1791 | |
| 1792 | /* Process each function ... */ |
| 1793 | functupdescs = (TupleDesc *) palloc(nfuncs * sizeof(TupleDesc)); |
| 1794 | |
| 1795 | totalatts = 0; |
| 1796 | funcno = 0; |
| 1797 | forthree(lc1, funcexprs, lc2, funcnames, lc3, coldeflists) |
| 1798 | { |
| 1799 | Node *funcexpr = (Node *) lfirst(lc1); |
| 1800 | char *funcname = (char *) lfirst(lc2); |
| 1801 | List *coldeflist = (List *) lfirst(lc3); |
no test coverage detected