68 bool *returning_flag);
79 const char *attrName);
90 int varno,
Query *parsetree,
bool *hasUpdate);
142 bool forUpdatePushedDown)
148 context.for_execute = forExecute;
154 foreach(l, parsetree->
rtable)
180 else if (forUpdatePushedDown)
185 lockmode = rte->rellockmode;
188 lockmode = rte->rellockmode;
196 rte->relkind = rel->
rd_rel->relkind;
215 foreach(ll, rte->joinaliasvars)
218 Var *aliasvar = aliasitem;
230 if (aliasvar &&
IsA(aliasvar,
Var))
242 if (aliasvar->
varno != curinputvarno)
244 curinputvarno = aliasvar->
varno;
245 if (curinputvarno >= rt_index)
246 elog(
ERROR,
"unexpected varno %d in JOIN RTE %d",
247 curinputvarno, rt_index);
248 curinputrte =
rt_fetch(curinputvarno,
258 newaliasvars =
lappend(newaliasvars, aliasitem);
260 rte->joinaliasvars = newaliasvars;
271 (forUpdatePushedDown ||
293 if (parsetree->hasSubLinks)
348 bool *returning_flag)
354 Query **sub_action_ptr;
373 current_varno = rt_index;
403 foreach(lc, sub_action->
rtable)
441 List *perminfos_tail = sub_action->rteperminfos;
449 sub_action->rteperminfos =
copyObject(parsetree->rteperminfos);
451 rtable_tail, perminfos_tail);
458 if (parsetree->hasSubLinks && !sub_action->hasSubLinks)
460 foreach(lc, parsetree->
rtable)
467 sub_action->hasSubLinks =
471 sub_action->hasSubLinks =
475 sub_action->hasSubLinks =
479 sub_action->hasSubLinks =
486 sub_action->hasSubLinks |=
488 if (sub_action->hasSubLinks)
500 sub_action->hasRowSecurity |= parsetree->hasRowSecurity;
527 if (newjointree !=
NIL)
537 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
538 errmsg(
"conditional UNION/INTERSECT/EXCEPT statements are not implemented")));
547 if (parsetree->hasSubLinks && !sub_action->hasSubLinks)
548 sub_action->hasSubLinks =
570 foreach(lc, parsetree->
cteList)
575 foreach(lc2, sub_action->
cteList)
581 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
582 errmsg(
"WITH query name \"%s\" appears in both a rule action and the query being rewritten",
591 sub_action->hasRecursive |= parsetree->hasRecursive;
592 sub_action->hasModifyingCTE |= parsetree->hasModifyingCTE;
606 if (sub_action->hasModifyingCTE && rule_action != sub_action)
608 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
609 errmsg(
"INSERT ... SELECT rule actions are not supported for queries having data-modifying statements in WITH")));
617 AddQual(sub_action, rule_qual);
632 sub_action = (
Query *)
644 *sub_action_ptr = sub_action;
646 rule_action = sub_action;
661 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
662 errmsg(
"cannot have RETURNING lists in multiple rules")));
663 *returning_flag =
true;
666 parsetree->resultRelation,
673 &rule_action->hasSubLinks);
679 if (parsetree->hasSubLinks && !rule_action->hasSubLinks)
680 rule_action->hasSubLinks =
703 foreach(l, newjointree)
763 int values_rte_index,
787 next_junk_attrno = numattrs + 1;
789 foreach(temp, targetList)
793 if (!old_tle->resjunk)
796 attrno = old_tle->
resno;
797 if (attrno < 1 || attrno > numattrs)
798 elog(
ERROR,
"bogus resno %d in targetlist", attrno);
802 if (att_tup->attisdropped)
806 new_tles[attrno - 1] =
808 new_tles[attrno - 1],
823 if (old_tle->
resno != next_junk_attrno)
826 old_tle->
resno = next_junk_attrno;
828 junk_tlist =
lappend(junk_tlist, old_tle);
833 for (attrno = 1; attrno <= numattrs; attrno++)
841 if (att_tup->attisdropped)
849 apply_default = ((new_tle == NULL && commandType ==
CMD_INSERT) ||
854 int values_attrno = 0;
857 if (values_rte && new_tle &&
IsA(new_tle->
expr,
Var))
861 if (var->
varno == values_rte_index)
870 if (att_tup->attidentity == ATTRIBUTE_IDENTITY_ALWAYS && !apply_default)
873 apply_default =
true;
882 if (values_attrno != 0)
884 if (default_only_cols == NULL)
888 apply_default =
true;
893 (
errcode(ERRCODE_GENERATED_ALWAYS),
894 errmsg(
"cannot insert a non-DEFAULT value into column \"%s\"",
896 errdetail(
"Column \"%s\" is an identity column defined as GENERATED ALWAYS.",
898 errhint(
"Use OVERRIDING SYSTEM VALUE to override.")));
907 if (att_tup->attidentity == ATTRIBUTE_IDENTITY_BY_DEFAULT &&
909 apply_default =
true;
915 if (att_tup->attgenerated && !apply_default)
921 if (values_attrno != 0)
923 if (default_only_cols == NULL)
927 apply_default =
true;
932 (
errcode(ERRCODE_GENERATED_ALWAYS),
933 errmsg(
"cannot insert a non-DEFAULT value into column \"%s\"",
935 errdetail(
"Column \"%s\" is a generated column.",
944 if (values_attrno != 0 && apply_default && unused_values_attrnos)
956 if (att_tup->attidentity == ATTRIBUTE_IDENTITY_ALWAYS &&
957 new_tle && !apply_default)
959 (
errcode(ERRCODE_GENERATED_ALWAYS),
960 errmsg(
"column \"%s\" can only be updated to DEFAULT",
962 errdetail(
"Column \"%s\" is an identity column defined as GENERATED ALWAYS.",
965 if (att_tup->attgenerated && new_tle && !apply_default)
967 (
errcode(ERRCODE_GENERATED_ALWAYS),
968 errmsg(
"column \"%s\" can only be updated to DEFAULT",
970 errdetail(
"Column \"%s\" is a generated column.",
974 if (att_tup->attgenerated)
981 else if (apply_default)
1002 att_tup->attcollation,
1026 new_tlist =
lappend(new_tlist, new_tle);
1044 const char *attrName)
1055 if (prior_tle == NULL)
1095 prior_expr = (
Node *) prior_tle->
expr;
1110 if (src_input == NULL ||
1111 prior_input == NULL ||
1114 (
errcode(ERRCODE_SYNTAX_ERROR),
1115 errmsg(
"multiple assignments to same column \"%s\"",
1121 priorbottom = prior_input;
1126 if (newbottom == NULL)
1128 priorbottom = newbottom;
1130 if (!
equal(priorbottom, src_input))
1132 (
errcode(ERRCODE_SYNTAX_ERROR),
1133 errmsg(
"multiple assignments to same column \"%s\"",
1146 memcpy(fstore, prior_expr,
sizeof(
FieldStore));
1157 memcpy(fstore, src_expr,
sizeof(
FieldStore));
1158 fstore->
arg = (
Expr *) prior_expr;
1160 newexpr = (
Node *) fstore;
1168 newexpr = (
Node *) sbsref;
1182 newcoerce->
arg = (
Expr *) newexpr;
1183 newexpr = (
Node *) newcoerce;
1228 Oid atttype = att_tup->atttypid;
1229 int32 atttypmod = att_tup->atttypmod;
1233 if (att_tup->attidentity)
1238 nve->
typeId = att_tup->atttypid;
1240 return (
Node *) nve;
1246 if (att_tup->atthasdef)
1250 elog(
ERROR,
"default expression not found for attribute %d of relation \"%s\"",
1258 if (expr == NULL && !att_tup->attgenerated)
1281 (
errcode(ERRCODE_DATATYPE_MISMATCH),
1282 errmsg(
"column \"%s\" is of type %s"
1283 " but default expression is of type %s",
1287 errhint(
"You will need to rewrite or cast the expression.")));
1304 foreach(lc2, sublist)
1332 if (default_only_cols == NULL)
1336 foreach(lc2, sublist)
1349 foreach(lc2, sublist)
1367 return default_only_cols;
1415 bool isAutoUpdatableView;
1440 attrnos = (
int *)
palloc0(numattrs *
sizeof(
int));
1454 Assert(attrno >= 1 && attrno <= numattrs);
1455 attrnos[attrno - 1] = tle->
resno;
1465 isAutoUpdatableView =
false;
1466 if (target_relation->
rd_rel->relkind == RELKIND_VIEW &&
1476 parsetree->resultRelation, parsetree, &hasUpdate);
1484 rule_lock->
qual == NULL)
1497 isAutoUpdatableView =
true;
1512 foreach(lc2, sublist)
1515 int attrno = attrnos[
i++];
1539 elog(
ERROR,
"cannot set value in column %d to DEFAULT",
i);
1540 Assert(attrno > 0 && attrno <= target_relation->rd_att->natts);
1543 if (!att_tup->attisdropped)
1555 if (isAutoUpdatableView)
1558 newList =
lappend(newList, col);
1559 allReplaced =
false;
1565 att_tup->attcollation,
1579 newList =
lappend(newList, new_expr);
1582 newList =
lappend(newList, col);
1584 newValues =
lappend(newValues, newList);
1616 foreach(lc2, sublist)
1629 newList =
lappend(newList, col);
1631 newValues =
lappend(newValues, newList);
1653 if (rulelocks == NULL)
1658 if (parsetree->resultRelation != varno)
1664 for (
i = 0;
i < nlocks;
i++)
1695 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1696 errmsg(
"cannot execute MERGE on relation \"%s\"",
1698 errdetail(
"MERGE is not supported for relations with rules."));
1701 if (oneLock->
event == event)
1705 matching_locks =
lappend(matching_locks, oneLock);
1709 return matching_locks;
1729 elog(
ERROR,
"expected just one rule action");
1730 if (
rule->qual != NULL)
1731 elog(
ERROR,
"cannot handle qualified ON SELECT rule");
1737 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1738 errmsg(
"access to non-system view \"%s\" is restricted",
1741 if (rt_index == parsetree->resultRelation)
1787 parsetree->resultRelation, 0);
1806 elog(
ERROR,
"unrecognized commandType: %d",
1869 while (
list_length(rte->eref->colnames) < numCols)
1871 rte->eref->colnames =
lappend(rte->eref->colnames,
1916 strength, waitPolicy,
true);
1936 elog(
ERROR,
"unrecognized node type: %d",
1974 (
void *) activeRIRs);
1988 int origResultRelation = parsetree->resultRelation;
1998 foreach(lc, parsetree->
cteList)
2002 if (cte->search_clause || cte->cycle_clause)
2054 if (rte->relkind == RELKIND_MATVIEW)
2075 if (rt_index != parsetree->resultRelation &&
2083 if (rt_index == parsetree->resultRelation &&
2084 rt_index != origResultRelation)
2100 for (
i = 0;
i <
rules->numLocks;
i++)
2118 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
2119 errmsg(
"infinite recursion detected in rules for relation \"%s\"",
2142 foreach(lc, parsetree->
cteList)
2154 if (parsetree->hasSubLinks)
2165 foreach(lc, parsetree->
rtable)
2169 List *securityQuals;
2170 List *withCheckOptions;
2171 bool hasRowSecurity;
2178 (rte->relkind != RELKIND_RELATION &&
2179 rte->relkind != RELKIND_PARTITIONED_TABLE))
2188 &securityQuals, &withCheckOptions,
2189 &hasRowSecurity, &hasSubLinks);
2191 if (securityQuals !=
NIL || withCheckOptions !=
NIL)
2203 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
2204 errmsg(
"infinite recursion detected in policy for relation \"%s\"",
2242 rte->securityQuals);
2244 parsetree->withCheckOptions =
list_concat(withCheckOptions,
2245 parsetree->withCheckOptions);
2253 parsetree->hasRowSecurity =
true;
2255 parsetree->hasSubLinks =
true;
2311 &parsetree->hasSubLinks);
2353 bool *returning_flag,
2354 Query **qual_product)
2362 Node *event_qual = rule_lock->
qual;
2370 if (event_qual != NULL)
2375 *instead_flag =
true;
2397 if (*qual_product == NULL)
2415 event_qual, rt_index, event,
2418 rule_action->querySource = qsrc;
2419 rule_action->canSetTag =
false;
2421 results =
lappend(results, rule_action);
2453 elog(
ERROR,
"invalid _RETURN rule action specification");
2459 elog(
ERROR,
"failed to find _RETURN rule for view");
2499 switch (
action->commandType)
2523 elog(
ERROR,
"unrecognized CmdType: %d", (
int) event);
2556 return gettext_noop(
"Junk view columns are not updatable.");
2561 return gettext_noop(
"View columns that are not columns of their base relation are not updatable.");
2564 return gettext_noop(
"View columns that refer to system columns are not updatable.");
2567 return gettext_noop(
"View columns that return whole-row references are not updatable.");
2628 return gettext_noop(
"Views containing DISTINCT are not automatically updatable.");
2631 return gettext_noop(
"Views containing GROUP BY are not automatically updatable.");
2634 return gettext_noop(
"Views containing HAVING are not automatically updatable.");
2637 return gettext_noop(
"Views containing UNION, INTERSECT, or EXCEPT are not automatically updatable.");
2640 return gettext_noop(
"Views containing WITH are not automatically updatable.");
2643 return gettext_noop(
"Views containing LIMIT or OFFSET are not automatically updatable.");
2654 if (viewquery->hasAggs)
2655 return gettext_noop(
"Views that return aggregate functions are not automatically updatable.");
2657 if (viewquery->hasWindowFuncs)
2658 return gettext_noop(
"Views that return window functions are not automatically updatable.");
2660 if (viewquery->hasTargetSRFs)
2661 return gettext_noop(
"Views that return set-returning functions are not automatically updatable.");
2668 return gettext_noop(
"Views that do not select from a single table or view are not automatically updatable.");
2672 return gettext_noop(
"Views that do not select from a single table or view are not automatically updatable.");
2676 (base_rte->relkind != RELKIND_RELATION &&
2677 base_rte->relkind != RELKIND_FOREIGN_TABLE &&
2678 base_rte->relkind != RELKIND_VIEW &&
2679 base_rte->relkind != RELKIND_PARTITIONED_TABLE))
2680 return gettext_noop(
"Views that do not select from a single table or view are not automatically updatable.");
2683 return gettext_noop(
"Views containing TABLESAMPLE are not automatically updatable.");
2707 return gettext_noop(
"Views that have no updatable columns are not automatically updatable.");
2741 char **non_updatable_col)
2755 if (updatable_cols != NULL)
2756 *updatable_cols = NULL;
2757 if (non_updatable_col != NULL)
2758 *non_updatable_col = NULL;
2765 const char *col_update_detail;
2770 if (col_update_detail == NULL)
2773 if (updatable_cols != NULL)
2779 if (non_updatable_col != NULL)
2780 *non_updatable_col = tle->resname;
2781 return col_update_detail;
2822 List *outer_reloids,
2823 bool include_triggers,
2830 #define ALL_EVENTS ((1 << CMD_INSERT) | (1 << CMD_UPDATE) | (1 << CMD_DELETE))
2854 if (rel->
rd_rel->relkind == RELKIND_RELATION ||
2855 rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
2863 if (rulelocks != NULL)
2885 if (include_triggers)
2908 if (rel->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
2930 if (rel->
rd_rel->relkind == RELKIND_VIEW)
2949 &updatable_cols, NULL);
2951 if (include_cols != NULL)
2969 if (base_rte->relkind != RELKIND_RELATION &&
2970 base_rte->relkind != RELKIND_PARTITIONED_TABLE)
2972 baseoid = base_rte->
relid;
2983 events |= auto_events;
3024 foreach(lc, targetlist)
3045 if (tle != NULL && !tle->resjunk &&
IsA(tle->
expr,
Var))
3053 elog(
ERROR,
"attribute number %d not found in view targetlist",
3078 List *mergeActionList,
3087 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3088 errmsg(
"cannot insert into view \"%s\"",
3091 errhint(
"To enable inserting into the view, provide an INSTEAD OF INSERT trigger or an unconditional ON INSERT DO INSTEAD rule."));
3095 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3096 errmsg(
"cannot update view \"%s\"",
3099 errhint(
"To enable updating the view, provide an INSTEAD OF UPDATE trigger or an unconditional ON UPDATE DO INSTEAD rule."));
3103 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3104 errmsg(
"cannot delete from view \"%s\"",
3107 errhint(
"To enable deleting from the view, provide an INSTEAD OF DELETE trigger or an unconditional ON DELETE DO INSTEAD rule."));
3117 switch (
action->commandType)
3122 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3123 errmsg(
"cannot insert into view \"%s\"",
3126 errhint(
"To enable inserting into the view using MERGE, provide an INSTEAD OF INSERT trigger."));
3131 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3132 errmsg(
"cannot update view \"%s\"",
3135 errhint(
"To enable updating the view using MERGE, provide an INSTEAD OF UPDATE trigger."));
3140 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3141 errmsg(
"cannot delete from view \"%s\"",
3144 errhint(
"To enable deleting from the view using MERGE, provide an INSTEAD OF DELETE trigger."));
3155 elog(
ERROR,
"unrecognized CmdType: %d", (
int) command);
3174 bool insert_or_update;
3175 const char *auto_update_detail;
3186 List *view_targetlist;
3199 view_rte =
rt_fetch(parsetree->resultRelation, parsetree->
rtable);
3218 insert_or_update =
true;
3228 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3229 errmsg(
"access to non-system view \"%s\" is restricted",
3238 auto_update_detail =
3241 if (auto_update_detail)
3245 auto_update_detail);
3251 if (insert_or_update)
3254 char *non_updatable_col;
3307 &non_updatable_col);
3308 if (auto_update_detail)
3318 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3319 errmsg(
"cannot insert into column \"%s\" of view \"%s\"",
3326 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3327 errmsg(
"cannot update column \"%s\" of view \"%s\"",
3334 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3335 errmsg(
"cannot merge into column \"%s\" of view \"%s\"",
3362 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3363 errmsg(
"cannot merge into view \"%s\"",
3365 errdetail(
"MERGE is not supported for views with INSTEAD OF triggers for some actions but not all."),
3366 errhint(
"To enable merging into the view, either provide a full set of INSTEAD OF triggers or drop the existing INSTEAD OF triggers."));
3395 base_rte->relkind = base_rel->
rd_rel->relkind;
3403 if (viewquery->hasSubLinks)
3434 new_rte->
inh =
false;
3470 new_rte->perminfoindex = 0;
3518 new_rte->securityQuals = view_rte->securityQuals;
3519 view_rte->securityQuals =
NIL;
3525 parsetree = (
Query *)
3527 parsetree->resultRelation,
3542 parsetree->resultRelation,
3545 Assert(parsetree->resultRelation == new_rt_index);
3568 if (view_tle != NULL && !view_tle->resjunk &&
IsA(view_tle->
expr,
Var))
3571 elog(
ERROR,
"attribute number %d not found in view targetlist",
3588 if (view_tle != NULL && !view_tle->resjunk &&
IsA(view_tle->
expr,
Var))
3589 tle->resno = ((
Var *) view_tle->
expr)->varattno;
3591 elog(
ERROR,
"attribute number %d not found in view targetlist",
3605 Index old_exclRelIndex,
3625 if (view_tle != NULL && !view_tle->resjunk &&
IsA(view_tle->
expr,
Var))
3628 elog(
ERROR,
"attribute number %d not found in view targetlist",
3647 new_exclRte = new_exclNSItem->
p_rte;
3648 new_exclRte->relkind = RELKIND_COMPOSITE_TYPE;
3650 new_exclRte->perminfoindex = 0;
3674 new_exclRelIndex, 0);
3684 &parsetree->hasSubLinks);
3724 new_rte->securityQuals =
lcons(viewqual, new_rte->securityQuals);
3735 if (!parsetree->hasSubLinks)
3748 if (insert_or_update)
3761 if (parsetree->withCheckOptions !=
NIL)
3782 if (has_wco && (cascaded || viewquery->
jointree->
quals != NULL))
3793 parsetree->withCheckOptions =
lcons(wco,
3794 parsetree->withCheckOptions);
3807 if (!parsetree->hasSubLinks &&
3835 bool instead =
false;
3836 bool returning =
false;
3837 bool updatableview =
false;
3838 Query *qual_product = NULL;
3847 foreach(lc1, parsetree->
cteList)
3878 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3879 errmsg(
"DO INSTEAD NOTIFY rules are not supported for data-modifying statements in WITH")));
3882 Assert(!ctequery->canSetTag);
3886 else if (newstuff ==
NIL)
3889 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3890 errmsg(
"DO INSTEAD NOTHING rules are not supported for data-modifying statements in WITH")));
3897 foreach(lc2, newstuff)
3903 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3904 errmsg(
"conditional DO INSTEAD rules are not supported for data-modifying statements in WITH")));
3907 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3908 errmsg(
"DO ALSO rules are not supported for data-modifying statements in WITH")));
3912 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3913 errmsg(
"multi-statement DO INSTEAD rules are not supported for data-modifying statements in WITH")));
3927 int result_relation;
3931 int product_orig_rt_length;
3932 List *product_queries;
3933 bool hasUpdate =
false;
3934 int values_rte_index = 0;
3935 bool defaults_remaining =
false;
3937 result_relation = parsetree->resultRelation;
3938 Assert(result_relation != 0);
3974 if (values_rte != NULL)
3975 elog(
ERROR,
"more than one VALUES RTE found");
3978 values_rte_index = rtr->
rtindex;
3985 Bitmapset *unused_values_attrnos = NULL;
3990 parsetree->override,
3994 &unused_values_attrnos);
3998 unused_values_attrnos))
3999 defaults_remaining =
true;
4007 parsetree->override,
4018 parsetree->override,
4029 parsetree->override,
4044 switch (
action->commandType)
4074 elog(
ERROR,
"unrecognized commandType: %d", (
int) event);
4080 result_relation, parsetree, &hasUpdate);
4099 if (defaults_remaining && product_queries !=
NIL)
4112 foreach(n, product_queries)
4138 elog(
ERROR,
"failed to find VALUES RTE in product query");
4160 rt_entry_relation->
rd_rel->relkind == RELKIND_VIEW &&
4169 if (qual_product != NULL)
4173 gettext_noop(
"Views with conditional DO INSTEAD rules are not automatically updatable."));
4189 product_queries =
lcons(parsetree, product_queries);
4191 product_queries =
lappend(product_queries, parsetree);
4202 updatableview =
true;
4209 if (product_queries !=
NIL)
4214 foreach(n, rewrite_events)
4218 rev->
event == event)
4220 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
4221 errmsg(
"infinite recursion detected in rules for relation \"%s\"",
4228 rewrite_events =
lappend(rewrite_events, rev);
4230 foreach(n, product_queries)
4247 product_orig_rt_length);
4261 if ((instead || qual_product != NULL) &&
4269 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4270 errmsg(
"cannot perform INSERT RETURNING on relation \"%s\"",
4272 errhint(
"You need an unconditional ON INSERT DO INSTEAD rule with a RETURNING clause.")));
4276 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4277 errmsg(
"cannot perform UPDATE RETURNING on relation \"%s\"",
4279 errhint(
"You need an unconditional ON UPDATE DO INSTEAD rule with a RETURNING clause.")));
4283 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4284 errmsg(
"cannot perform DELETE RETURNING on relation \"%s\"",
4286 errhint(
"You need an unconditional ON DELETE DO INSTEAD rule with a RETURNING clause.")));
4289 elog(
ERROR,
"unrecognized commandType: %d",
4300 (product_queries !=
NIL || hasUpdate) &&
4303 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4304 errmsg(
"INSERT with ON CONFLICT clause cannot be used with table that has INSERT or UPDATE rules")));
4325 if (qual_product != NULL)
4326 rewritten =
lcons(qual_product, rewritten);
4328 rewritten =
lcons(parsetree, rewritten);
4332 if (qual_product != NULL)
4333 rewritten =
lappend(rewritten, qual_product);
4335 rewritten =
lappend(rewritten, parsetree);
4351 foreach(lc1, rewritten)
4360 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4361 errmsg(
"WITH cannot be used in a query that is rewritten by rules into multiple queries")));
4380 uint64 input_query_id = parsetree->queryId;
4385 bool foundOriginalQuery;
4392 Assert(parsetree->canSetTag);
4409 foreach(l, querylist)
4415 query->queryId = input_query_id;
4417 results =
lappend(results, query);
4437 foundOriginalQuery =
false;
4446 Assert(query->canSetTag);
4447 Assert(!foundOriginalQuery);
4448 foundOriginalQuery =
true;
4449 #ifndef USE_ASSERT_CHECKING
4455 Assert(!query->canSetTag);
4459 lastInstead = query;
4463 if (!foundOriginalQuery && lastInstead != NULL)
4464 lastInstead->canSetTag =
true;
#define InvalidAttrNumber
int bms_next_member(const Bitmapset *a, int prevbit)
bool bms_is_member(int x, const Bitmapset *a)
Bitmapset * bms_add_member(Bitmapset *a, int x)
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_int_members(Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_del_member(Bitmapset *a, int x)
#define Assert(condition)
int errdetail_internal(const char *fmt,...)
int errdetail(const char *fmt,...)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
bool equal(const void *a, const void *b)
int ExecCleanTargetListLength(List *targetlist)
FdwRoutine * GetFdwRoutineForRelation(Relation relation, bool makecopy)
if(TABLE==NULL||TABLE_index==NULL)
List * lappend(List *list, void *datum)
List * lappend_oid(List *list, Oid datum)
bool list_member_oid(const List *list, Oid datum)
List * list_concat(List *list1, const List *list2)
List * lcons(void *datum, List *list)
List * list_concat_copy(const List *list1, const List *list2)
List * list_delete_last(List *list)
Node * get_typdefault(Oid typid)
Alias * makeAlias(const char *aliasname, List *colnames)
Var * makeWholeRowVar(RangeTblEntry *rte, int varno, Index varlevelsup, bool allowScalar)
TargetEntry * makeTargetEntry(Expr *expr, AttrNumber resno, char *resname, bool resjunk)
Const * makeNullConst(Oid consttype, int32 consttypmod, Oid constcollid)
Const * makeConst(Oid consttype, int32 consttypmod, Oid constcollid, int constlen, Datum constvalue, bool constisnull, bool constbyval)
TargetEntry * flatCopyTargetEntry(TargetEntry *src_tle)
char * pstrdup(const char *in)
void pfree(void *pointer)
void * palloc0(Size size)
Oid exprType(const Node *expr)
Node * strip_implicit_coercions(Node *node)
#define query_tree_walker(q, w, c, f)
#define expression_tree_walker(n, w, c)
#define QTW_IGNORE_RC_SUBQUERIES
#define IsA(nodeptr, _type_)
#define castNode(_type_, nodeptr)
Node * coerce_to_domain(Node *arg, Oid baseTypeId, int32 baseTypeMod, Oid typeId, CoercionContext ccontext, CoercionForm cformat, int location, bool hideInputCoercion)
Node * coerce_to_target_type(ParseState *pstate, Node *expr, Oid exprtype, Oid targettype, int32 targettypmod, CoercionContext ccontext, CoercionForm cformat, int location)
ParseState * make_parsestate(ParseState *parentParseState)
RTEPermissionInfo * addRTEPermissionInfo(List **rteperminfos, RangeTblEntry *rte)
RowMarkClause * get_parse_rowmark(Query *qry, Index rtindex)
ParseNamespaceItem * addRangeTableEntryForRelation(ParseState *pstate, Relation rel, int lockmode, Alias *alias, bool inh, bool inFromCl)
bool get_rte_attribute_is_dropped(RangeTblEntry *rte, AttrNumber attnum)
RTEPermissionInfo * getRTEPermissionInfo(List *rteperminfos, RangeTblEntry *rte)
TargetEntry * get_tle_by_resno(List *tlist, AttrNumber resno)
#define ACL_SELECT_FOR_UPDATE
void applyLockingClause(Query *qry, Index rtindex, LockClauseStrength strength, LockWaitPolicy waitPolicy, bool pushedDown)
List * BuildOnConflictExcludedTargetlist(Relation targetrel, Index exclRelIndex)
#define rt_fetch(rangetable_index, rangetable)
FormData_pg_attribute * Form_pg_attribute
Oid getIdentitySequence(Relation rel, AttrNumber attnum, bool missing_ok)
#define lfirst_node(type, lc)
static int list_length(const List *l)
#define linitial_node(type, l)
#define foreach_delete_current(lst, var_or_cell)
#define foreach_node(type, var, lst)
int restrict_nonsystem_relation_kind
void check_stack_depth(void)
@ OVERRIDING_SYSTEM_VALUE
#define RelationGetRelid(relation)
#define RelationHasCheckOption(relation)
#define RelationHasSecurityInvoker(relation)
#define RelationGetNumberOfAttributes(relation)
#define RelationGetRelationName(relation)
#define RelationHasCascadedCheckOption(relation)
#define RelationIsSecurityView(relation)
#define RULE_FIRES_ON_ORIGIN
#define RULE_FIRES_ON_REPLICA
static void markQueryForLocking(Query *qry, Node *jtnode, LockClauseStrength strength, LockWaitPolicy waitPolicy, bool pushedDown)
static Query * rewriteRuleAction(Query *parsetree, Query *rule_action, Node *rule_qual, int rt_index, CmdType event, bool *returning_flag)
static List * fireRules(Query *parsetree, int rt_index, CmdType event, List *locks, bool *instead_flag, bool *returning_flag, Query **qual_product)
static TargetEntry * process_matched_tle(TargetEntry *src_tle, TargetEntry *prior_tle, const char *attrName)
static List * adjustJoinTreeList(Query *parsetree, bool removert, int rt_index)
void AcquireRewriteLocks(Query *parsetree, bool forExecute, bool forUpdatePushedDown)
bool view_has_instead_trigger(Relation view, CmdType event, List *mergeActionList)
const char * view_query_is_auto_updatable(Query *viewquery, bool check_cols)
int relation_is_updatable(Oid reloid, List *outer_reloids, bool include_triggers, Bitmapset *include_cols)
static Query * CopyAndAddInvertedQual(Query *parsetree, Node *rule_qual, int rt_index, CmdType event)
List * QueryRewrite(Query *parsetree)
static bool acquireLocksOnSubLinks(Node *node, acquireLocksOnSubLinks_context *context)
static bool rewriteValuesRTE(Query *parsetree, RangeTblEntry *rte, int rti, Relation target_relation, Bitmapset *unused_cols)
static Node * get_assignment_input(Node *node)
static Bitmapset * adjust_view_column_set(Bitmapset *cols, List *targetlist)
struct acquireLocksOnSubLinks_context acquireLocksOnSubLinks_context
static bool fireRIRonSubLink(Node *node, List *activeRIRs)
static bool searchForDefault(RangeTblEntry *rte)
static List * RewriteQuery(Query *parsetree, List *rewrite_events, int orig_rt_length)
struct rewrite_event rewrite_event
static Query * fireRIRrules(Query *parsetree, List *activeRIRs)
static const char * view_cols_are_auto_updatable(Query *viewquery, Bitmapset *required_cols, Bitmapset **updatable_cols, char **non_updatable_col)
static Bitmapset * findDefaultOnlyColumns(RangeTblEntry *rte)
static void rewriteValuesRTEToNulls(Query *parsetree, RangeTblEntry *rte)
Query * get_view_query(Relation view)
static List * matchLocks(CmdType event, Relation relation, int varno, Query *parsetree, bool *hasUpdate)
void error_view_not_updatable(Relation view, CmdType command, List *mergeActionList, const char *detail)
static Query * ApplyRetrieveRule(Query *parsetree, RewriteRule *rule, int rt_index, Relation relation, List *activeRIRs)
static List * rewriteTargetListIU(List *targetList, CmdType commandType, OverridingKind override, Relation target_relation, RangeTblEntry *values_rte, int values_rte_index, Bitmapset **unused_values_attrnos)
static Query * rewriteTargetView(Query *parsetree, Relation view)
static const char * view_col_is_auto_updatable(RangeTblRef *rtr, TargetEntry *tle)
Node * build_column_default(Relation rel, int attrno)
Node * ReplaceVarsFromTargetList(Node *node, int target_varno, int sublevels_up, RangeTblEntry *target_rte, List *targetlist, ReplaceVarsNoMatchOption nomatch_option, int nomatch_varno, bool *outer_hasSubLinks)
void ChangeVarNodes(Node *node, int rt_index, int new_index, int sublevels_up)
void OffsetVarNodes(Node *node, int offset, int sublevels_up)
bool checkExprHasSubLink(Node *node)
Query * getInsertSelectQuery(Query *parsetree, Query ***subquery_ptr)
void CombineRangeTables(List **dst_rtable, List **dst_perminfos, List *src_rtable, List *src_perminfos)
void AddQual(Query *parsetree, Node *qual)
bool rangeTableEntry_used(Node *node, int rt_index, int sublevels_up)
void AddInvertedQual(Query *parsetree, Node *qual)
@ REPLACEVARS_SUBSTITUTE_NULL
@ REPLACEVARS_CHANGE_VARNO
@ REPLACEVARS_REPORT_ERROR
CommonTableExpr * rewriteSearchAndCycle(CommonTableExpr *cte)
void get_row_security_policies(Query *root, RangeTblEntry *rte, int rt_index, List **securityQuals, List **withCheckOptions, bool *hasRowSecurity, bool *hasSubLinks)
void relation_close(Relation relation, LOCKMODE lockmode)
Relation try_relation_open(Oid relationId, LOCKMODE lockmode)
ExecForeignInsert_function ExecForeignInsert
ExecForeignUpdate_function ExecForeignUpdate
ExecForeignDelete_function ExecForeignDelete
IsForeignRelUpdatable_function IsForeignRelUpdatable
OnConflictExpr * onConflict
struct TableSampleClause * tablesample
LockClauseStrength strength
LockWaitPolicy waitPolicy
bool trig_update_instead_row
bool trig_delete_instead_row
bool trig_insert_instead_row
#define FirstLowInvalidHeapAttributeNumber
void table_close(Relation relation, LOCKMODE lockmode)
Relation table_open(Oid relationId, LOCKMODE lockmode)
#define RESTRICT_RELKIND_VIEW
#define FirstNormalObjectId
int SessionReplicationRole
#define SESSION_REPLICATION_ROLE_REPLICA
Node * TupleDescGetDefault(TupleDesc tupdesc, AttrNumber attnum)
#define TupleDescAttr(tupdesc, i)
String * makeString(char *str)
bool contain_vars_of_level(Node *node, int levelsup)
static struct rule * rules