* checkInsertTargets - * generate a list of INSERT column targets if not supplied, or * test supplied column names to make sure they are in target table. * Also return an integer list of the columns' attribute numbers. */
| 1010 | * Also return an integer list of the columns' attribute numbers. |
| 1011 | */ |
| 1012 | List * |
| 1013 | checkInsertTargets(ParseState *pstate, List *cols, List **attrnos) |
| 1014 | { |
| 1015 | *attrnos = NIL; |
| 1016 | |
| 1017 | if (cols == NIL) |
| 1018 | { |
| 1019 | /* |
| 1020 | * Generate default column list for INSERT. |
| 1021 | */ |
| 1022 | int numcol = RelationGetNumberOfAttributes(pstate->p_target_relation); |
| 1023 | |
| 1024 | int i; |
| 1025 | |
| 1026 | for (i = 0; i < numcol; i++) |
| 1027 | { |
| 1028 | ResTarget *col; |
| 1029 | Form_pg_attribute attr; |
| 1030 | |
| 1031 | attr = TupleDescAttr(pstate->p_target_relation->rd_att, i); |
| 1032 | |
| 1033 | if (attr->attisdropped) |
| 1034 | continue; |
| 1035 | |
| 1036 | col = makeNode(ResTarget); |
| 1037 | col->name = pstrdup(NameStr(attr->attname)); |
| 1038 | col->indirection = NIL; |
| 1039 | col->val = NULL; |
| 1040 | col->location = -1; |
| 1041 | cols = lappend(cols, col); |
| 1042 | *attrnos = lappend_int(*attrnos, i + 1); |
| 1043 | } |
| 1044 | } |
| 1045 | else |
| 1046 | { |
| 1047 | /* |
| 1048 | * Do initial validation of user-supplied INSERT column list. |
| 1049 | */ |
| 1050 | Bitmapset *wholecols = NULL; |
| 1051 | Bitmapset *partialcols = NULL; |
| 1052 | ListCell *tl; |
| 1053 | |
| 1054 | foreach(tl, cols) |
| 1055 | { |
| 1056 | ResTarget *col = (ResTarget *) lfirst(tl); |
| 1057 | char *name = col->name; |
| 1058 | int attrno; |
| 1059 | |
| 1060 | /* Lookup column name, ereport on failure */ |
| 1061 | attrno = attnameAttNum(pstate->p_target_relation, name, false); |
| 1062 | if (attrno == InvalidAttrNumber) |
| 1063 | ereport(ERROR, |
| 1064 | (errcode(ERRCODE_UNDEFINED_COLUMN), |
| 1065 | errmsg("column \"%s\" of relation \"%s\" does not exist", |
| 1066 | name, |
| 1067 | RelationGetRelationName(pstate->p_target_relation)), |
| 1068 | parser_errposition(pstate, col->location))); |
| 1069 |
no test coverage detected