* transformAssignedExpr() * This is used in INSERT and UPDATE statements only. It prepares an * expression for assignment to a column of the target table. * This includes coercing the given value to the target column's type * (if necessary), and dealing with any subfield names or subscripts * attached to the target column itself. The input expression has * already been through transformExp
| 453 | * exprLocation(expr) for errors that can happen in a default INSERT. |
| 454 | */ |
| 455 | Expr * |
| 456 | transformAssignedExpr(ParseState *pstate, |
| 457 | Expr *expr, |
| 458 | ParseExprKind exprKind, |
| 459 | const char *colname, |
| 460 | int attrno, |
| 461 | List *indirection, |
| 462 | int location) |
| 463 | { |
| 464 | Relation rd = pstate->p_target_relation; |
| 465 | Oid type_id; /* type of value provided */ |
| 466 | Oid attrtype; /* type of target column */ |
| 467 | int32 attrtypmod; |
| 468 | Oid attrcollation; /* collation of target column */ |
| 469 | ParseExprKind sv_expr_kind; |
| 470 | |
| 471 | /* |
| 472 | * Save and restore identity of expression type we're parsing. We must |
| 473 | * set p_expr_kind here because we can parse subscripts without going |
| 474 | * through transformExpr(). |
| 475 | */ |
| 476 | Assert(exprKind != EXPR_KIND_NONE); |
| 477 | sv_expr_kind = pstate->p_expr_kind; |
| 478 | pstate->p_expr_kind = exprKind; |
| 479 | |
| 480 | Assert(rd != NULL); |
| 481 | if (attrno <= 0) |
| 482 | ereport(ERROR, |
| 483 | (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), |
| 484 | errmsg("cannot assign to system column \"%s\"", |
| 485 | colname), |
| 486 | parser_errposition(pstate, location))); |
| 487 | attrtype = attnumTypeId(rd, attrno); |
| 488 | attrtypmod = TupleDescAttr(rd->rd_att, attrno - 1)->atttypmod; |
| 489 | attrcollation = TupleDescAttr(rd->rd_att, attrno - 1)->attcollation; |
| 490 | |
| 491 | /* |
| 492 | * If the expression is a DEFAULT placeholder, insert the attribute's |
| 493 | * type/typmod/collation into it so that exprType etc will report the |
| 494 | * right things. (We expect that the eventually substituted default |
| 495 | * expression will in fact have this type and typmod. The collation |
| 496 | * likely doesn't matter, but let's set it correctly anyway.) Also, |
| 497 | * reject trying to update a subfield or array element with DEFAULT, since |
| 498 | * there can't be any default for portions of a column. |
| 499 | */ |
| 500 | if (expr && IsA(expr, SetToDefault)) |
| 501 | { |
| 502 | SetToDefault *def = (SetToDefault *) expr; |
| 503 | |
| 504 | def->typeId = attrtype; |
| 505 | def->typeMod = attrtypmod; |
| 506 | def->collation = attrcollation; |
| 507 | if (indirection) |
| 508 | { |
| 509 | if (IsA(linitial(indirection), A_Indices)) |
| 510 | ereport(ERROR, |
| 511 | (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), |
| 512 | errmsg("cannot set an array element to DEFAULT"), |
no test coverage detected