74 bool *returning_flag);
85 const char *attrName);
96 int varno,
Query *parsetree,
bool *hasUpdate);
148 bool forUpdatePushedDown)
154 context.for_execute = forExecute;
160 foreach(l, parsetree->
rtable)
186 else if (forUpdatePushedDown)
191 lockmode = rte->rellockmode;
194 lockmode = rte->rellockmode;
202 rte->relkind = rel->
rd_rel->relkind;
221 foreach(ll, rte->joinaliasvars)
224 Var *aliasvar = aliasitem;
236 if (aliasvar &&
IsA(aliasvar,
Var))
248 if (aliasvar->
varno != curinputvarno)
250 curinputvarno = aliasvar->
varno;
251 if (curinputvarno >= rt_index)
252 elog(
ERROR,
"unexpected varno %d in JOIN RTE %d",
253 curinputvarno, rt_index);
254 curinputrte =
rt_fetch(curinputvarno,
264 newaliasvars =
lappend(newaliasvars, aliasitem);
266 rte->joinaliasvars = newaliasvars;
277 (forUpdatePushedDown ||
299 if (parsetree->hasSubLinks)
354 bool *returning_flag)
360 Query **sub_action_ptr;
379 current_varno = rt_index;
409 foreach(lc, sub_action->
rtable)
447 List *perminfos_tail = sub_action->rteperminfos;
455 sub_action->rteperminfos =
copyObject(parsetree->rteperminfos);
457 rtable_tail, perminfos_tail);
464 if (parsetree->hasSubLinks && !sub_action->hasSubLinks)
466 foreach(lc, parsetree->
rtable)
473 sub_action->hasSubLinks =
477 sub_action->hasSubLinks =
481 sub_action->hasSubLinks =
485 sub_action->hasSubLinks =
492 sub_action->hasSubLinks |=
494 if (sub_action->hasSubLinks)
506 sub_action->hasRowSecurity |= parsetree->hasRowSecurity;
533 if (newjointree !=
NIL)
543 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
544 errmsg(
"conditional UNION/INTERSECT/EXCEPT statements are not implemented")));
553 if (parsetree->hasSubLinks && !sub_action->hasSubLinks)
554 sub_action->hasSubLinks =
576 foreach(lc, parsetree->
cteList)
581 foreach(lc2, sub_action->
cteList)
587 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
588 errmsg(
"WITH query name \"%s\" appears in both a rule action and the query being rewritten",
597 sub_action->hasRecursive |= parsetree->hasRecursive;
598 sub_action->hasModifyingCTE |= parsetree->hasModifyingCTE;
612 if (sub_action->hasModifyingCTE && rule_action != sub_action)
614 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
615 errmsg(
"INSERT ... SELECT rule actions are not supported for queries having data-modifying statements in WITH")));
623 AddQual(sub_action, rule_qual);
638 sub_action = (
Query *)
650 *sub_action_ptr = sub_action;
652 rule_action = sub_action;
667 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
668 errmsg(
"cannot have RETURNING lists in multiple rules")));
669 *returning_flag =
true;
672 parsetree->resultRelation,
679 &rule_action->hasSubLinks);
685 if (parsetree->hasSubLinks && !rule_action->hasSubLinks)
686 rule_action->hasSubLinks =
709 foreach(l, newjointree)
769 int values_rte_index,
793 next_junk_attrno = numattrs + 1;
795 foreach(temp, targetList)
799 if (!old_tle->resjunk)
802 attrno = old_tle->
resno;
803 if (attrno < 1 || attrno > numattrs)
804 elog(
ERROR,
"bogus resno %d in targetlist", attrno);
808 if (att_tup->attisdropped)
812 new_tles[attrno - 1] =
814 new_tles[attrno - 1],
829 if (old_tle->
resno != next_junk_attrno)
832 old_tle->
resno = next_junk_attrno;
834 junk_tlist =
lappend(junk_tlist, old_tle);
839 for (attrno = 1; attrno <= numattrs; attrno++)
847 if (att_tup->attisdropped)
855 apply_default = ((new_tle == NULL && commandType ==
CMD_INSERT) ||
860 int values_attrno = 0;
863 if (values_rte && new_tle &&
IsA(new_tle->
expr,
Var))
867 if (var->
varno == values_rte_index)
876 if (att_tup->attidentity == ATTRIBUTE_IDENTITY_ALWAYS && !apply_default)
879 apply_default =
true;
888 if (values_attrno != 0)
890 if (default_only_cols == NULL)
894 apply_default =
true;
899 (
errcode(ERRCODE_GENERATED_ALWAYS),
900 errmsg(
"cannot insert a non-DEFAULT value into column \"%s\"",
902 errdetail(
"Column \"%s\" is an identity column defined as GENERATED ALWAYS.",
904 errhint(
"Use OVERRIDING SYSTEM VALUE to override.")));
913 if (att_tup->attidentity == ATTRIBUTE_IDENTITY_BY_DEFAULT &&
915 apply_default =
true;
921 if (att_tup->attgenerated && !apply_default)
927 if (values_attrno != 0)
929 if (default_only_cols == NULL)
933 apply_default =
true;
938 (
errcode(ERRCODE_GENERATED_ALWAYS),
939 errmsg(
"cannot insert a non-DEFAULT value into column \"%s\"",
941 errdetail(
"Column \"%s\" is a generated column.",
950 if (values_attrno != 0 && apply_default && unused_values_attrnos)
962 if (att_tup->attidentity == ATTRIBUTE_IDENTITY_ALWAYS &&
963 new_tle && !apply_default)
965 (
errcode(ERRCODE_GENERATED_ALWAYS),
966 errmsg(
"column \"%s\" can only be updated to DEFAULT",
968 errdetail(
"Column \"%s\" is an identity column defined as GENERATED ALWAYS.",
971 if (att_tup->attgenerated && new_tle && !apply_default)
973 (
errcode(ERRCODE_GENERATED_ALWAYS),
974 errmsg(
"column \"%s\" can only be updated to DEFAULT",
976 errdetail(
"Column \"%s\" is a generated column.",
980 if (att_tup->attgenerated)
987 else if (apply_default)
1008 att_tup->attcollation,
1032 new_tlist =
lappend(new_tlist, new_tle);
1050 const char *attrName)
1061 if (prior_tle == NULL)
1101 prior_expr = (
Node *) prior_tle->
expr;
1116 if (src_input == NULL ||
1117 prior_input == NULL ||
1120 (
errcode(ERRCODE_SYNTAX_ERROR),
1121 errmsg(
"multiple assignments to same column \"%s\"",
1127 priorbottom = prior_input;
1132 if (newbottom == NULL)
1134 priorbottom = newbottom;
1136 if (!
equal(priorbottom, src_input))
1138 (
errcode(ERRCODE_SYNTAX_ERROR),
1139 errmsg(
"multiple assignments to same column \"%s\"",
1152 memcpy(fstore, prior_expr,
sizeof(
FieldStore));
1163 memcpy(fstore, src_expr,
sizeof(
FieldStore));
1164 fstore->
arg = (
Expr *) prior_expr;
1166 newexpr = (
Node *) fstore;
1174 newexpr = (
Node *) sbsref;
1188 newcoerce->
arg = (
Expr *) newexpr;
1189 newexpr = (
Node *) newcoerce;
1234 Oid atttype = att_tup->atttypid;
1235 int32 atttypmod = att_tup->atttypmod;
1239 if (att_tup->attidentity)
1244 nve->
typeId = att_tup->atttypid;
1246 return (
Node *) nve;
1252 if (att_tup->atthasdef)
1256 elog(
ERROR,
"default expression not found for attribute %d of relation \"%s\"",
1264 if (expr == NULL && !att_tup->attgenerated)
1287 (
errcode(ERRCODE_DATATYPE_MISMATCH),
1288 errmsg(
"column \"%s\" is of type %s"
1289 " but default expression is of type %s",
1293 errhint(
"You will need to rewrite or cast the expression.")));
1310 foreach(lc2, sublist)
1338 if (default_only_cols == NULL)
1342 foreach(lc2, sublist)
1355 foreach(lc2, sublist)
1373 return default_only_cols;
1421 bool isAutoUpdatableView;
1446 attrnos = (
int *)
palloc0(numattrs *
sizeof(
int));
1460 Assert(attrno >= 1 && attrno <= numattrs);
1461 attrnos[attrno - 1] = tle->
resno;
1471 isAutoUpdatableView =
false;
1472 if (target_relation->
rd_rel->relkind == RELKIND_VIEW &&
1482 parsetree->resultRelation, parsetree, &hasUpdate);
1490 rule_lock->
qual == NULL)
1503 isAutoUpdatableView =
true;
1518 foreach(lc2, sublist)
1521 int attrno = attrnos[
i++];
1545 elog(
ERROR,
"cannot set value in column %d to DEFAULT",
i);
1546 Assert(attrno > 0 && attrno <= target_relation->rd_att->natts);
1549 if (!att_tup->attisdropped)
1561 if (isAutoUpdatableView)
1564 newList =
lappend(newList, col);
1565 allReplaced =
false;
1571 att_tup->attcollation,
1585 newList =
lappend(newList, new_expr);
1588 newList =
lappend(newList, col);
1590 newValues =
lappend(newValues, newList);
1622 foreach(lc2, sublist)
1635 newList =
lappend(newList, col);
1637 newValues =
lappend(newValues, newList);
1659 if (rulelocks == NULL)
1664 if (parsetree->resultRelation != varno)
1670 for (
i = 0;
i < nlocks;
i++)
1701 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1702 errmsg(
"cannot execute MERGE on relation \"%s\"",
1704 errdetail(
"MERGE is not supported for relations with rules."));
1707 if (oneLock->
event == event)
1711 matching_locks =
lappend(matching_locks, oneLock);
1715 return matching_locks;
1735 elog(
ERROR,
"expected just one rule action");
1736 if (
rule->qual != NULL)
1737 elog(
ERROR,
"cannot handle qualified ON SELECT rule");
1743 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1744 errmsg(
"access to non-system view \"%s\" is restricted",
1747 if (rt_index == parsetree->resultRelation)
1793 parsetree->resultRelation, 0);
1812 elog(
ERROR,
"unrecognized commandType: %d",
1852 parsetree->hasRowSecurity |= rule_action->hasRowSecurity;
1881 while (
list_length(rte->eref->colnames) < numCols)
1883 rte->eref->colnames =
lappend(rte->eref->colnames,
1928 strength, waitPolicy,
true);
1948 elog(
ERROR,
"unrecognized node type: %d",
2005 int origResultRelation = parsetree->resultRelation;
2015 foreach(lc, parsetree->
cteList)
2019 if (cte->search_clause || cte->cycle_clause)
2057 parsetree->hasRowSecurity |= rte->
subquery->hasRowSecurity;
2078 if (rte->relkind == RELKIND_MATVIEW)
2099 if (rt_index != parsetree->resultRelation &&
2107 if (rt_index == parsetree->resultRelation &&
2108 rt_index != origResultRelation)
2124 for (
i = 0;
i <
rules->numLocks;
i++)
2142 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
2143 errmsg(
"infinite recursion detected in rules for relation \"%s\"",
2166 foreach(lc, parsetree->
cteList)
2177 parsetree->hasRowSecurity |= ((
Query *) cte->
ctequery)->hasRowSecurity;
2184 if (parsetree->hasSubLinks)
2188 context.activeRIRs = activeRIRs;
2189 context.hasRowSecurity =
false;
2198 parsetree->hasRowSecurity |=
context.hasRowSecurity;
2208 foreach(lc, parsetree->
rtable)
2212 List *securityQuals;
2213 List *withCheckOptions;
2214 bool hasRowSecurity;
2221 (rte->relkind != RELKIND_RELATION &&
2222 rte->relkind != RELKIND_PARTITIONED_TABLE))
2231 &securityQuals, &withCheckOptions,
2232 &hasRowSecurity, &hasSubLinks);
2234 if (securityQuals !=
NIL || withCheckOptions !=
NIL)
2247 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
2248 errmsg(
"infinite recursion detected in policy for relation \"%s\"",
2296 rte->securityQuals);
2298 parsetree->withCheckOptions =
list_concat(withCheckOptions,
2299 parsetree->withCheckOptions);
2307 parsetree->hasRowSecurity =
true;
2309 parsetree->hasSubLinks =
true;
2365 &parsetree->hasSubLinks);
2407 bool *returning_flag,
2408 Query **qual_product)
2416 Node *event_qual = rule_lock->
qual;
2424 if (event_qual != NULL)
2429 *instead_flag =
true;
2451 if (*qual_product == NULL)
2469 event_qual, rt_index, event,
2472 rule_action->querySource = qsrc;
2473 rule_action->canSetTag =
false;
2475 results =
lappend(results, rule_action);
2507 elog(
ERROR,
"invalid _RETURN rule action specification");
2513 elog(
ERROR,
"failed to find _RETURN rule for view");
2553 switch (
action->commandType)
2577 elog(
ERROR,
"unrecognized CmdType: %d", (
int) event);
2610 return gettext_noop(
"Junk view columns are not updatable.");
2615 return gettext_noop(
"View columns that are not columns of their base relation are not updatable.");
2618 return gettext_noop(
"View columns that refer to system columns are not updatable.");
2621 return gettext_noop(
"View columns that return whole-row references are not updatable.");
2682 return gettext_noop(
"Views containing DISTINCT are not automatically updatable.");
2685 return gettext_noop(
"Views containing GROUP BY are not automatically updatable.");
2688 return gettext_noop(
"Views containing HAVING are not automatically updatable.");
2691 return gettext_noop(
"Views containing UNION, INTERSECT, or EXCEPT are not automatically updatable.");
2694 return gettext_noop(
"Views containing WITH are not automatically updatable.");
2697 return gettext_noop(
"Views containing LIMIT or OFFSET are not automatically updatable.");
2708 if (viewquery->hasAggs)
2709 return gettext_noop(
"Views that return aggregate functions are not automatically updatable.");
2711 if (viewquery->hasWindowFuncs)
2712 return gettext_noop(
"Views that return window functions are not automatically updatable.");
2714 if (viewquery->hasTargetSRFs)
2715 return gettext_noop(
"Views that return set-returning functions are not automatically updatable.");
2722 return gettext_noop(
"Views that do not select from a single table or view are not automatically updatable.");
2726 return gettext_noop(
"Views that do not select from a single table or view are not automatically updatable.");
2730 (base_rte->relkind != RELKIND_RELATION &&
2731 base_rte->relkind != RELKIND_FOREIGN_TABLE &&
2732 base_rte->relkind != RELKIND_VIEW &&
2733 base_rte->relkind != RELKIND_PARTITIONED_TABLE))
2734 return gettext_noop(
"Views that do not select from a single table or view are not automatically updatable.");
2737 return gettext_noop(
"Views containing TABLESAMPLE are not automatically updatable.");
2761 return gettext_noop(
"Views that have no updatable columns are not automatically updatable.");
2795 char **non_updatable_col)
2809 if (updatable_cols != NULL)
2810 *updatable_cols = NULL;
2811 if (non_updatable_col != NULL)
2812 *non_updatable_col = NULL;
2819 const char *col_update_detail;
2824 if (col_update_detail == NULL)
2827 if (updatable_cols != NULL)
2833 if (non_updatable_col != NULL)
2834 *non_updatable_col = tle->resname;
2835 return col_update_detail;
2876 List *outer_reloids,
2877 bool include_triggers,
2884 #define ALL_EVENTS ((1 << CMD_INSERT) | (1 << CMD_UPDATE) | (1 << CMD_DELETE))
2908 if (rel->
rd_rel->relkind == RELKIND_RELATION ||
2909 rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
2917 if (rulelocks != NULL)
2939 if (include_triggers)
2962 if (rel->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
2984 if (rel->
rd_rel->relkind == RELKIND_VIEW)
3003 &updatable_cols, NULL);
3005 if (include_cols != NULL)
3023 if (base_rte->relkind != RELKIND_RELATION &&
3024 base_rte->relkind != RELKIND_PARTITIONED_TABLE)
3026 baseoid = base_rte->
relid;
3037 events |= auto_events;
3078 foreach(lc, targetlist)
3099 if (tle != NULL && !tle->resjunk &&
IsA(tle->
expr,
Var))
3107 elog(
ERROR,
"attribute number %d not found in view targetlist",
3132 List *mergeActionList,
3141 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3142 errmsg(
"cannot insert into view \"%s\"",
3145 errhint(
"To enable inserting into the view, provide an INSTEAD OF INSERT trigger or an unconditional ON INSERT DO INSTEAD rule."));
3149 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3150 errmsg(
"cannot update view \"%s\"",
3153 errhint(
"To enable updating the view, provide an INSTEAD OF UPDATE trigger or an unconditional ON UPDATE DO INSTEAD rule."));
3157 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3158 errmsg(
"cannot delete from view \"%s\"",
3161 errhint(
"To enable deleting from the view, provide an INSTEAD OF DELETE trigger or an unconditional ON DELETE DO INSTEAD rule."));
3171 switch (
action->commandType)
3176 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3177 errmsg(
"cannot insert into view \"%s\"",
3180 errhint(
"To enable inserting into the view using MERGE, provide an INSTEAD OF INSERT trigger."));
3185 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3186 errmsg(
"cannot update view \"%s\"",
3189 errhint(
"To enable updating the view using MERGE, provide an INSTEAD OF UPDATE trigger."));
3194 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3195 errmsg(
"cannot delete from view \"%s\"",
3198 errhint(
"To enable deleting from the view using MERGE, provide an INSTEAD OF DELETE trigger."));
3209 elog(
ERROR,
"unrecognized CmdType: %d", (
int) command);
3228 bool insert_or_update;
3229 const char *auto_update_detail;
3240 List *view_targetlist;
3253 view_rte =
rt_fetch(parsetree->resultRelation, parsetree->
rtable);
3272 insert_or_update =
true;
3282 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3283 errmsg(
"access to non-system view \"%s\" is restricted",
3292 auto_update_detail =
3295 if (auto_update_detail)
3299 auto_update_detail);
3305 if (insert_or_update)
3308 char *non_updatable_col;
3361 &non_updatable_col);
3362 if (auto_update_detail)
3372 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3373 errmsg(
"cannot insert into column \"%s\" of view \"%s\"",
3380 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3381 errmsg(
"cannot update column \"%s\" of view \"%s\"",
3388 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3389 errmsg(
"cannot merge into column \"%s\" of view \"%s\"",
3416 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3417 errmsg(
"cannot merge into view \"%s\"",
3419 errdetail(
"MERGE is not supported for views with INSTEAD OF triggers for some actions but not all."),
3420 errhint(
"To enable merging into the view, either provide a full set of INSTEAD OF triggers or drop the existing INSTEAD OF triggers."));
3449 base_rte->relkind = base_rel->
rd_rel->relkind;
3457 if (viewquery->hasSubLinks)
3488 new_rte->
inh =
false;
3524 new_rte->perminfoindex = 0;
3572 new_rte->securityQuals = view_rte->securityQuals;
3573 view_rte->securityQuals =
NIL;
3579 parsetree = (
Query *)
3581 parsetree->resultRelation,
3596 parsetree->resultRelation,
3599 Assert(parsetree->resultRelation == new_rt_index);
3622 if (view_tle != NULL && !view_tle->resjunk &&
IsA(view_tle->
expr,
Var))
3625 elog(
ERROR,
"attribute number %d not found in view targetlist",
3642 if (view_tle != NULL && !view_tle->resjunk &&
IsA(view_tle->
expr,
Var))
3643 tle->resno = ((
Var *) view_tle->
expr)->varattno;
3645 elog(
ERROR,
"attribute number %d not found in view targetlist",
3659 Index old_exclRelIndex,
3679 if (view_tle != NULL && !view_tle->resjunk &&
IsA(view_tle->
expr,
Var))
3682 elog(
ERROR,
"attribute number %d not found in view targetlist",
3701 new_exclRte = new_exclNSItem->
p_rte;
3702 new_exclRte->relkind = RELKIND_COMPOSITE_TYPE;
3704 new_exclRte->perminfoindex = 0;
3728 new_exclRelIndex, 0);
3738 &parsetree->hasSubLinks);
3778 new_rte->securityQuals =
lcons(viewqual, new_rte->securityQuals);
3789 if (!parsetree->hasSubLinks)
3802 if (insert_or_update)
3815 if (parsetree->withCheckOptions !=
NIL)
3836 if (has_wco && (cascaded || viewquery->
jointree->
quals != NULL))
3847 parsetree->withCheckOptions =
lcons(wco,
3848 parsetree->withCheckOptions);
3861 if (!parsetree->hasSubLinks &&
3889 bool instead =
false;
3890 bool returning =
false;
3891 bool updatableview =
false;
3892 Query *qual_product = NULL;
3901 foreach(lc1, parsetree->
cteList)
3932 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3933 errmsg(
"DO INSTEAD NOTIFY rules are not supported for data-modifying statements in WITH")));
3936 Assert(!ctequery->canSetTag);
3940 else if (newstuff ==
NIL)
3943 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3944 errmsg(
"DO INSTEAD NOTHING rules are not supported for data-modifying statements in WITH")));
3951 foreach(lc2, newstuff)
3957 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3958 errmsg(
"conditional DO INSTEAD rules are not supported for data-modifying statements in WITH")));
3961 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3962 errmsg(
"DO ALSO rules are not supported for data-modifying statements in WITH")));
3966 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3967 errmsg(
"multi-statement DO INSTEAD rules are not supported for data-modifying statements in WITH")));
3981 int result_relation;
3985 int product_orig_rt_length;
3986 List *product_queries;
3987 bool hasUpdate =
false;
3988 int values_rte_index = 0;
3989 bool defaults_remaining =
false;
3991 result_relation = parsetree->resultRelation;
3992 Assert(result_relation != 0);
4028 if (values_rte != NULL)
4029 elog(
ERROR,
"more than one VALUES RTE found");
4032 values_rte_index = rtr->
rtindex;
4039 Bitmapset *unused_values_attrnos = NULL;
4044 parsetree->override,
4048 &unused_values_attrnos);
4052 unused_values_attrnos))
4053 defaults_remaining =
true;
4061 parsetree->override,
4072 parsetree->override,
4083 parsetree->override,
4098 switch (
action->commandType)
4128 elog(
ERROR,
"unrecognized commandType: %d", (
int) event);
4134 result_relation, parsetree, &hasUpdate);
4153 if (defaults_remaining && product_queries !=
NIL)
4166 foreach(n, product_queries)
4192 elog(
ERROR,
"failed to find VALUES RTE in product query");
4214 rt_entry_relation->
rd_rel->relkind == RELKIND_VIEW &&
4223 if (qual_product != NULL)
4227 gettext_noop(
"Views with conditional DO INSTEAD rules are not automatically updatable."));
4243 product_queries =
lcons(parsetree, product_queries);
4245 product_queries =
lappend(product_queries, parsetree);
4256 updatableview =
true;
4263 if (product_queries !=
NIL)
4268 foreach(n, rewrite_events)
4272 rev->
event == event)
4274 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
4275 errmsg(
"infinite recursion detected in rules for relation \"%s\"",
4282 rewrite_events =
lappend(rewrite_events, rev);
4284 foreach(n, product_queries)
4301 product_orig_rt_length);
4315 if ((instead || qual_product != NULL) &&
4323 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4324 errmsg(
"cannot perform INSERT RETURNING on relation \"%s\"",
4326 errhint(
"You need an unconditional ON INSERT DO INSTEAD rule with a RETURNING clause.")));
4330 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4331 errmsg(
"cannot perform UPDATE RETURNING on relation \"%s\"",
4333 errhint(
"You need an unconditional ON UPDATE DO INSTEAD rule with a RETURNING clause.")));
4337 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4338 errmsg(
"cannot perform DELETE RETURNING on relation \"%s\"",
4340 errhint(
"You need an unconditional ON DELETE DO INSTEAD rule with a RETURNING clause.")));
4343 elog(
ERROR,
"unrecognized commandType: %d",
4354 (product_queries !=
NIL || hasUpdate) &&
4357 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4358 errmsg(
"INSERT with ON CONFLICT clause cannot be used with table that has INSERT or UPDATE rules")));
4379 if (qual_product != NULL)
4380 rewritten =
lcons(qual_product, rewritten);
4382 rewritten =
lcons(parsetree, rewritten);
4386 if (qual_product != NULL)
4387 rewritten =
lappend(rewritten, qual_product);
4389 rewritten =
lappend(rewritten, parsetree);
4405 foreach(lc1, rewritten)
4414 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4415 errmsg(
"WITH cannot be used in a query that is rewritten by rules into multiple queries")));
4434 uint64 input_query_id = parsetree->queryId;
4439 bool foundOriginalQuery;
4446 Assert(parsetree->canSetTag);
4463 foreach(l, querylist)
4469 query->queryId = input_query_id;
4471 results =
lappend(results, query);
4491 foundOriginalQuery =
false;
4500 Assert(query->canSetTag);
4501 Assert(!foundOriginalQuery);
4502 foundOriginalQuery =
true;
4503 #ifndef USE_ASSERT_CHECKING
4509 Assert(!query->canSetTag);
4513 lastInstead = query;
4517 if (!foundOriginalQuery && lastInstead != NULL)
4518 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 bool fireRIRonSubLink(Node *node, fireRIRonSubLink_context *context)
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)
struct fireRIRonSubLink_context fireRIRonSubLink_context
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 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