The only place that used p_is_insert was transformAssignedExpr(),
which used it to distinguish INSERT from UPDATE when handling
indirection on assignment target columns -- see commit
c1ca3a19df3.
However, this information is already available to
transformAssignedExpr() via its exprKind parameter, which is always
either EXPR_KIND_INSERT_TARGET or EXPR_KIND_UPDATE_TARGET.
As noted in the commit message for
c1ca3a19df3, this use of
p_is_insert isn't particularly pretty, so have transformAssignedExpr()
use the exprKind parameter instead. This then allows p_is_insert to be
removed entirely, which simplifies state management in a few other
places across the parser.
Author: Viktor Holmberg <v@viktorh.net>
Reviewed-by: Dean Rasheed <dean.a.rasheed@gmail.com>
Discussion: https://postgr.es/m/
badc3b4c-da73-4000-b8d3-
638a6f53a769@Spark
Assert(pstate->p_ctenamespace == NIL);
qry->commandType = CMD_INSERT;
- pstate->p_is_insert = true;
/* process the WITH clause independently of all else */
if (stmt->withClause)
/* Process DO UPDATE */
if (onConflictClause->action == ONCONFLICT_UPDATE)
{
- /*
- * Expressions in the UPDATE targetlist need to be handled like UPDATE
- * not INSERT. We don't need to save/restore this because all INSERT
- * expressions have been parsed already.
- */
- pstate->p_is_insert = false;
-
/*
* Add the EXCLUDED pseudo relation to the query namespace, making it
* available in the UPDATE subexpressions.
Node *qual;
qry->commandType = CMD_UPDATE;
- pstate->p_is_insert = false;
/* process the WITH clause independently of all else */
if (stmt->withClause)
List *icolumns;
List *attrnos;
- pstate->p_is_insert = true;
-
icolumns = checkInsertTargets(pstate,
mergeWhenClause->targetList,
&attrnos);
}
break;
case CMD_UPDATE:
- {
- pstate->p_is_insert = false;
- action->targetList =
- transformUpdateTargetList(pstate,
- mergeWhenClause->targetList);
- }
+ action->targetList =
+ transformUpdateTargetList(pstate,
+ mergeWhenClause->targetList);
break;
case CMD_DELETE:
break;
* pstate parse state
* expr expression to be modified
* exprKind indicates which type of statement we're dealing with
+ * (EXPR_KIND_INSERT_TARGET or EXPR_KIND_UPDATE_TARGET)
* colname target column name (ie, name of attribute to be assigned to)
* attrno target attribute number
* indirection subscripts/field names for target column, if any
* set p_expr_kind here because we can parse subscripts without going
* through transformExpr().
*/
- Assert(exprKind != EXPR_KIND_NONE);
+ Assert(exprKind == EXPR_KIND_INSERT_TARGET ||
+ exprKind == EXPR_KIND_UPDATE_TARGET);
sv_expr_kind = pstate->p_expr_kind;
pstate->p_expr_kind = exprKind;
{
Node *colVar;
- if (pstate->p_is_insert)
+ if (exprKind == EXPR_KIND_INSERT_TARGET)
{
/*
* The command is INSERT INTO table (col.something) ... so there
*
* p_grouping_nsitem: the ParseNamespaceItem that represents the grouping step.
*
- * p_is_insert: true to process assignment expressions like INSERT, false
- * to process them like UPDATE. (Note this can change intra-statement, for
- * cases like INSERT ON CONFLICT UPDATE.)
- *
* p_windowdefs: list of WindowDefs representing WINDOW and OVER clauses.
* We collect these while transforming expressions and then transform them
* afterwards (so that any resjunk tlist items needed for the sort/group
Relation p_target_relation; /* INSERT/UPDATE/DELETE/MERGE target rel */
ParseNamespaceItem *p_target_nsitem; /* target rel's NSItem, or NULL */
ParseNamespaceItem *p_grouping_nsitem; /* NSItem for grouping, or NULL */
- bool p_is_insert; /* process assignment like INSERT not UPDATE */
List *p_windowdefs; /* raw representations of window clauses */
ParseExprKind p_expr_kind; /* what kind of expression we're parsing */
int p_next_resno; /* next targetlist resno to assign */