* addTargetToGroupList * If the given targetlist entry isn't already in the SortGroupClause * list, add it to the end of the list, using default sort/group * semantics. * * This is very similar to addTargetToSortList, except that we allow the * case where only a grouping (equality) operator can be found, and that * the TLE is considered "already in the list" if it appears there with any
| 3715 | * Returns the updated SortGroupClause list. |
| 3716 | */ |
| 3717 | static List * |
| 3718 | addTargetToGroupList(ParseState *pstate, TargetEntry *tle, |
| 3719 | List *grouplist, List *targetlist, int location) |
| 3720 | { |
| 3721 | Oid restype = exprType((Node *) tle->expr); |
| 3722 | |
| 3723 | /* if tlist item is an UNKNOWN literal, change it to TEXT */ |
| 3724 | if (restype == UNKNOWNOID) |
| 3725 | { |
| 3726 | tle->expr = (Expr *) coerce_type(pstate, (Node *) tle->expr, |
| 3727 | restype, TEXTOID, -1, |
| 3728 | COERCION_IMPLICIT, |
| 3729 | COERCE_IMPLICIT_CAST, |
| 3730 | -1); |
| 3731 | restype = TEXTOID; |
| 3732 | } |
| 3733 | |
| 3734 | /* avoid making duplicate grouplist entries */ |
| 3735 | if (!targetIsInSortList(tle, InvalidOid, grouplist)) |
| 3736 | { |
| 3737 | SortGroupClause *grpcl = makeNode(SortGroupClause); |
| 3738 | Oid sortop; |
| 3739 | Oid eqop; |
| 3740 | bool hashable; |
| 3741 | ParseCallbackState pcbstate; |
| 3742 | |
| 3743 | setup_parser_errposition_callback(&pcbstate, pstate, location); |
| 3744 | |
| 3745 | /* determine the eqop and optional sortop */ |
| 3746 | get_sort_group_operators(restype, |
| 3747 | false, true, false, |
| 3748 | &sortop, &eqop, NULL, |
| 3749 | &hashable); |
| 3750 | |
| 3751 | cancel_parser_errposition_callback(&pcbstate); |
| 3752 | |
| 3753 | grpcl->tleSortGroupRef = assignSortGroupRef(tle, targetlist); |
| 3754 | grpcl->eqop = eqop; |
| 3755 | grpcl->sortop = sortop; |
| 3756 | grpcl->nulls_first = false; /* OK with or without sortop */ |
| 3757 | grpcl->hashable = hashable; |
| 3758 | |
| 3759 | grouplist = lappend(grouplist, grpcl); |
| 3760 | } |
| 3761 | |
| 3762 | return grouplist; |
| 3763 | } |
| 3764 | |
| 3765 | /* |
| 3766 | * assignSortGroupRef |
no test coverage detected