* FigureColnameInternal - * internal workhorse for FigureColname * * Return value indicates strength of confidence in result: * 0 - no information * 1 - second-best name choice * 2 - good name choice * The return value is actually only used internally. * If the result isn't zero, *name is set to the chosen name. */
| 1733 | * If the result isn't zero, *name is set to the chosen name. |
| 1734 | */ |
| 1735 | static int |
| 1736 | FigureColnameInternal(Node *node, char **name) |
| 1737 | { |
| 1738 | int strength = 0; |
| 1739 | |
| 1740 | if (node == NULL) |
| 1741 | return strength; |
| 1742 | |
| 1743 | switch (nodeTag(node)) |
| 1744 | { |
| 1745 | case T_ColumnRef: |
| 1746 | { |
| 1747 | char *fname = NULL; |
| 1748 | ListCell *l; |
| 1749 | |
| 1750 | /* find last field name, if any, ignoring "*" */ |
| 1751 | foreach(l, ((ColumnRef *) node)->fields) |
| 1752 | { |
| 1753 | Node *i = lfirst(l); |
| 1754 | |
| 1755 | if (IsA(i, String)) |
| 1756 | fname = strVal(i); |
| 1757 | } |
| 1758 | if (fname) |
| 1759 | { |
| 1760 | *name = fname; |
| 1761 | return 2; |
| 1762 | } |
| 1763 | } |
| 1764 | break; |
| 1765 | case T_A_Indirection: |
| 1766 | { |
| 1767 | A_Indirection *ind = (A_Indirection *) node; |
| 1768 | char *fname = NULL; |
| 1769 | ListCell *l; |
| 1770 | |
| 1771 | /* find last field name, if any, ignoring "*" and subscripts */ |
| 1772 | foreach(l, ind->indirection) |
| 1773 | { |
| 1774 | Node *i = lfirst(l); |
| 1775 | |
| 1776 | if (IsA(i, String)) |
| 1777 | fname = strVal(i); |
| 1778 | } |
| 1779 | if (fname) |
| 1780 | { |
| 1781 | *name = fname; |
| 1782 | return 2; |
| 1783 | } |
| 1784 | return FigureColnameInternal(ind->arg, name); |
| 1785 | } |
| 1786 | break; |
| 1787 | case T_FuncCall: |
| 1788 | *name = strVal(llast(((FuncCall *) node)->funcname)); |
| 1789 | return 2; |
| 1790 | case T_A_Expr: |
| 1791 | if (((A_Expr *) node)->kind == AEXPR_NULLIF) |
| 1792 | { |
no test coverage detected