* transformUpdateTargetList - * handle SET clause in UPDATE/INSERT ... ON CONFLICT UPDATE */
| 2884 | * handle SET clause in UPDATE/INSERT ... ON CONFLICT UPDATE |
| 2885 | */ |
| 2886 | static List * |
| 2887 | transformUpdateTargetList(ParseState *pstate, List *origTlist) |
| 2888 | { |
| 2889 | List *tlist = NIL; |
| 2890 | RangeTblEntry *target_rte; |
| 2891 | ListCell *orig_tl; |
| 2892 | ListCell *tl; |
| 2893 | |
| 2894 | tlist = transformTargetList(pstate, origTlist, |
| 2895 | EXPR_KIND_UPDATE_SOURCE); |
| 2896 | |
| 2897 | /* Prepare to assign non-conflicting resnos to resjunk attributes */ |
| 2898 | if (pstate->p_next_resno <= RelationGetNumberOfAttributes(pstate->p_target_relation)) |
| 2899 | pstate->p_next_resno = RelationGetNumberOfAttributes(pstate->p_target_relation) + 1; |
| 2900 | |
| 2901 | /* Prepare non-junk columns for assignment to target table */ |
| 2902 | target_rte = pstate->p_target_nsitem->p_rte; |
| 2903 | orig_tl = list_head(origTlist); |
| 2904 | |
| 2905 | foreach(tl, tlist) |
| 2906 | { |
| 2907 | TargetEntry *tle = (TargetEntry *) lfirst(tl); |
| 2908 | ResTarget *origTarget; |
| 2909 | int attrno; |
| 2910 | |
| 2911 | if (tle->resjunk) |
| 2912 | { |
| 2913 | /* |
| 2914 | * Resjunk nodes need no additional processing, but be sure they |
| 2915 | * have resnos that do not match any target columns; else rewriter |
| 2916 | * or planner might get confused. They don't need a resname |
| 2917 | * either. |
| 2918 | */ |
| 2919 | tle->resno = (AttrNumber) pstate->p_next_resno++; |
| 2920 | tle->resname = NULL; |
| 2921 | continue; |
| 2922 | } |
| 2923 | if (orig_tl == NULL) |
| 2924 | elog(ERROR, "UPDATE target count mismatch --- internal error"); |
| 2925 | origTarget = lfirst_node(ResTarget, orig_tl); |
| 2926 | |
| 2927 | attrno = attnameAttNum(pstate->p_target_relation, |
| 2928 | origTarget->name, true); |
| 2929 | if (attrno == InvalidAttrNumber) |
| 2930 | ereport(ERROR, |
| 2931 | (errcode(ERRCODE_UNDEFINED_COLUMN), |
| 2932 | errmsg("column \"%s\" of relation \"%s\" does not exist", |
| 2933 | origTarget->name, |
| 2934 | RelationGetRelationName(pstate->p_target_relation)), |
| 2935 | parser_errposition(pstate, origTarget->location))); |
| 2936 | |
| 2937 | updateTargetListEntry(pstate, tle, origTarget->name, |
| 2938 | attrno, |
| 2939 | origTarget->indirection, |
| 2940 | origTarget->location); |
| 2941 | |
| 2942 | /* Mark the target column as requiring update permissions */ |
| 2943 | target_rte->updatedCols = bms_add_member(target_rte->updatedCols, |
no test coverage detected