74 bool *returning_flag);
85 const char *attrName);
96 int varno,
Query *parsetree,
bool *hasUpdate);
150 bool forUpdatePushedDown)
162 foreach(l, parsetree->
rtable)
188 else if (forUpdatePushedDown)
193 lockmode = rte->rellockmode;
196 lockmode = rte->rellockmode;
204 rte->relkind = rel->
rd_rel->relkind;
223 foreach(ll, rte->joinaliasvars)
226 Var *aliasvar = aliasitem;
238 if (aliasvar &&
IsA(aliasvar,
Var))
250 if (aliasvar->
varno != curinputvarno)
252 curinputvarno = aliasvar->
varno;
253 if (curinputvarno >= rt_index)
254 elog(
ERROR,
"unexpected varno %d in JOIN RTE %d",
255 curinputvarno, rt_index);
256 curinputrte =
rt_fetch(curinputvarno,
266 newaliasvars =
lappend(newaliasvars, aliasitem);
268 rte->joinaliasvars = newaliasvars;
279 (forUpdatePushedDown ||
301 if (parsetree->hasSubLinks)
356 bool *returning_flag)
362 Query **sub_action_ptr;
381 current_varno = rt_index;
411 foreach(lc, sub_action->
rtable)
449 List *perminfos_tail = sub_action->rteperminfos;
457 sub_action->rteperminfos =
copyObject(parsetree->rteperminfos);
459 rtable_tail, perminfos_tail);
466 if (parsetree->hasSubLinks && !sub_action->hasSubLinks)
468 foreach(lc, parsetree->
rtable)
475 sub_action->hasSubLinks =
479 sub_action->hasSubLinks =
483 sub_action->hasSubLinks =
487 sub_action->hasSubLinks =
494 sub_action->hasSubLinks |=
496 if (sub_action->hasSubLinks)
508 sub_action->hasRowSecurity |= parsetree->hasRowSecurity;
535 if (newjointree !=
NIL)
545 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
546 errmsg(
"conditional UNION/INTERSECT/EXCEPT statements are not implemented")));
555 if (parsetree->hasSubLinks && !sub_action->hasSubLinks)
556 sub_action->hasSubLinks =
578 foreach(lc, parsetree->
cteList)
583 foreach(lc2, sub_action->
cteList)
589 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
590 errmsg(
"WITH query name \"%s\" appears in both a rule action and the query being rewritten",
599 sub_action->hasRecursive |= parsetree->hasRecursive;
600 sub_action->hasModifyingCTE |= parsetree->hasModifyingCTE;
614 if (sub_action->hasModifyingCTE && rule_action != sub_action)
616 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
617 errmsg(
"INSERT ... SELECT rule actions are not supported for queries having data-modifying statements in WITH")));
625 AddQual(sub_action, rule_qual);
640 sub_action = (
Query *)
646 sub_action->resultRelation,
653 *sub_action_ptr = sub_action;
655 rule_action = sub_action;
670 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
671 errmsg(
"cannot have RETURNING lists in multiple rules")));
672 *returning_flag =
true;
675 parsetree->resultRelation,
680 rule_action->resultRelation,
683 &rule_action->hasSubLinks);
686 rule_action->returningOldAlias = parsetree->returningOldAlias;
687 rule_action->returningNewAlias = parsetree->returningNewAlias;
693 if (parsetree->hasSubLinks && !rule_action->hasSubLinks)
694 rule_action->hasSubLinks =
717 foreach(l, newjointree)
777 int values_rte_index,
801 next_junk_attrno = numattrs + 1;
803 foreach(temp, targetList)
807 if (!old_tle->resjunk)
810 attrno = old_tle->
resno;
811 if (attrno < 1 || attrno > numattrs)
812 elog(
ERROR,
"bogus resno %d in targetlist", attrno);
816 if (att_tup->attisdropped)
820 new_tles[attrno - 1] =
822 new_tles[attrno - 1],
837 if (old_tle->
resno != next_junk_attrno)
840 old_tle->
resno = next_junk_attrno;
842 junk_tlist =
lappend(junk_tlist, old_tle);
847 for (attrno = 1; attrno <= numattrs; attrno++)
855 if (att_tup->attisdropped)
863 apply_default = ((new_tle == NULL && commandType ==
CMD_INSERT) ||
868 int values_attrno = 0;
871 if (values_rte && new_tle &&
IsA(new_tle->
expr,
Var))
875 if (var->
varno == values_rte_index)
884 if (att_tup->attidentity == ATTRIBUTE_IDENTITY_ALWAYS && !apply_default)
887 apply_default =
true;
896 if (values_attrno != 0)
898 if (default_only_cols == NULL)
902 apply_default =
true;
907 (
errcode(ERRCODE_GENERATED_ALWAYS),
908 errmsg(
"cannot insert a non-DEFAULT value into column \"%s\"",
910 errdetail(
"Column \"%s\" is an identity column defined as GENERATED ALWAYS.",
912 errhint(
"Use OVERRIDING SYSTEM VALUE to override.")));
921 if (att_tup->attidentity == ATTRIBUTE_IDENTITY_BY_DEFAULT &&
923 apply_default =
true;
930 if (att_tup->attgenerated && !apply_default)
936 if (values_attrno != 0)
938 if (default_only_cols == NULL)
942 apply_default =
true;
947 (
errcode(ERRCODE_GENERATED_ALWAYS),
948 errmsg(
"cannot insert a non-DEFAULT value into column \"%s\"",
950 errdetail(
"Column \"%s\" is a generated column.",
959 if (values_attrno != 0 && apply_default && unused_values_attrnos)
971 if (att_tup->attidentity == ATTRIBUTE_IDENTITY_ALWAYS &&
972 new_tle && !apply_default)
974 (
errcode(ERRCODE_GENERATED_ALWAYS),
975 errmsg(
"column \"%s\" can only be updated to DEFAULT",
977 errdetail(
"Column \"%s\" is an identity column defined as GENERATED ALWAYS.",
980 if (att_tup->attgenerated && new_tle && !apply_default)
982 (
errcode(ERRCODE_GENERATED_ALWAYS),
983 errmsg(
"column \"%s\" can only be updated to DEFAULT",
985 errdetail(
"Column \"%s\" is a generated column.",
989 if (att_tup->attgenerated)
997 else if (apply_default)
1017 att_tup->attcollation,
1030 new_tlist =
lappend(new_tlist, new_tle);
1048 const char *attrName)
1059 if (prior_tle == NULL)
1099 prior_expr = (
Node *) prior_tle->
expr;
1114 if (src_input == NULL ||
1115 prior_input == NULL ||
1118 (
errcode(ERRCODE_SYNTAX_ERROR),
1119 errmsg(
"multiple assignments to same column \"%s\"",
1125 priorbottom = prior_input;
1130 if (newbottom == NULL)
1132 priorbottom = newbottom;
1134 if (!
equal(priorbottom, src_input))
1136 (
errcode(ERRCODE_SYNTAX_ERROR),
1137 errmsg(
"multiple assignments to same column \"%s\"",
1150 memcpy(fstore, prior_expr,
sizeof(
FieldStore));
1161 memcpy(fstore, src_expr,
sizeof(
FieldStore));
1162 fstore->
arg = (
Expr *) prior_expr;
1164 newexpr = (
Node *) fstore;
1172 newexpr = (
Node *) sbsref;
1186 newcoerce->
arg = (
Expr *) newexpr;
1187 newexpr = (
Node *) newcoerce;
1232 Oid atttype = att_tup->atttypid;
1233 int32 atttypmod = att_tup->atttypmod;
1237 if (att_tup->attidentity)
1242 nve->
typeId = att_tup->atttypid;
1244 return (
Node *) nve;
1250 if (att_tup->atthasdef)
1254 elog(
ERROR,
"default expression not found for attribute %d of relation \"%s\"",
1262 if (expr == NULL && !att_tup->attgenerated)
1285 (
errcode(ERRCODE_DATATYPE_MISMATCH),
1286 errmsg(
"column \"%s\" is of type %s"
1287 " but default expression is of type %s",
1291 errhint(
"You will need to rewrite or cast the expression.")));
1308 foreach(lc2, sublist)
1336 if (default_only_cols == NULL)
1340 foreach(lc2, sublist)
1353 foreach(lc2, sublist)
1371 return default_only_cols;
1419 bool isAutoUpdatableView;
1444 attrnos = (
int *)
palloc0(numattrs *
sizeof(
int));
1458 Assert(attrno >= 1 && attrno <= numattrs);
1459 attrnos[attrno - 1] = tle->
resno;
1469 isAutoUpdatableView =
false;
1470 if (target_relation->
rd_rel->relkind == RELKIND_VIEW &&
1480 parsetree->resultRelation, parsetree, &hasUpdate);
1488 rule_lock->
qual == NULL)
1501 isAutoUpdatableView =
true;
1516 foreach(lc2, sublist)
1519 int attrno = attrnos[
i++];
1543 elog(
ERROR,
"cannot set value in column %d to DEFAULT",
i);
1544 Assert(attrno > 0 && attrno <= target_relation->rd_att->natts);
1547 if (!att_tup->attisdropped)
1559 if (isAutoUpdatableView)
1562 newList =
lappend(newList, col);
1563 allReplaced =
false;
1569 att_tup->attcollation,
1573 newList =
lappend(newList, new_expr);
1576 newList =
lappend(newList, col);
1578 newValues =
lappend(newValues, newList);
1610 foreach(lc2, sublist)
1623 newList =
lappend(newList, col);
1625 newValues =
lappend(newValues, newList);
1647 if (rulelocks == NULL)
1652 if (parsetree->resultRelation != varno)
1658 for (
i = 0;
i < nlocks;
i++)
1689 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1690 errmsg(
"cannot execute MERGE on relation \"%s\"",
1692 errdetail(
"MERGE is not supported for relations with rules."));
1695 if (oneLock->
event == event)
1699 matching_locks =
lappend(matching_locks, oneLock);
1703 return matching_locks;
1723 elog(
ERROR,
"expected just one rule action");
1724 if (
rule->qual != NULL)
1725 elog(
ERROR,
"cannot handle qualified ON SELECT rule");
1731 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1732 errmsg(
"access to non-system view \"%s\" is restricted",
1735 if (rt_index == parsetree->resultRelation)
1781 parsetree->resultRelation, 0);
1800 elog(
ERROR,
"unrecognized commandType: %d",
1840 parsetree->hasRowSecurity |= rule_action->hasRowSecurity;
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",
1993 int origResultRelation = parsetree->resultRelation;
2003 foreach(lc, parsetree->
cteList)
2007 if (cte->search_clause || cte->cycle_clause)
2045 parsetree->hasRowSecurity |= rte->
subquery->hasRowSecurity;
2066 if (rte->relkind == RELKIND_MATVIEW)
2087 if (rt_index != parsetree->resultRelation &&
2095 if (rt_index == parsetree->resultRelation &&
2096 rt_index != origResultRelation)
2112 for (
i = 0;
i <
rules->numLocks;
i++)
2130 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
2131 errmsg(
"infinite recursion detected in rules for relation \"%s\"",
2154 foreach(lc, parsetree->
cteList)
2165 parsetree->hasRowSecurity |= ((
Query *) cte->
ctequery)->hasRowSecurity;
2172 if (parsetree->hasSubLinks)
2196 foreach(lc, parsetree->
rtable)
2200 List *securityQuals;
2201 List *withCheckOptions;
2202 bool hasRowSecurity;
2209 (rte->relkind != RELKIND_RELATION &&
2210 rte->relkind != RELKIND_PARTITIONED_TABLE))
2219 &securityQuals, &withCheckOptions,
2220 &hasRowSecurity, &hasSubLinks);
2222 if (securityQuals !=
NIL || withCheckOptions !=
NIL)
2235 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
2236 errmsg(
"infinite recursion detected in policy for relation \"%s\"",
2284 rte->securityQuals);
2286 parsetree->withCheckOptions =
list_concat(withCheckOptions,
2287 parsetree->withCheckOptions);
2295 parsetree->hasRowSecurity =
true;
2297 parsetree->hasSubLinks =
true;
2349 parsetree->resultRelation,
2354 &parsetree->hasSubLinks);
2396 bool *returning_flag,
2397 Query **qual_product)
2405 Node *event_qual = rule_lock->
qual;
2413 if (event_qual != NULL)
2418 *instead_flag =
true;
2440 if (*qual_product == NULL)
2458 event_qual, rt_index, event,
2461 rule_action->querySource = qsrc;
2462 rule_action->canSetTag =
false;
2464 results =
lappend(results, rule_action);
2496 elog(
ERROR,
"invalid _RETURN rule action specification");
2502 elog(
ERROR,
"failed to find _RETURN rule for view");
2542 switch (
action->commandType)
2566 elog(
ERROR,
"unrecognized CmdType: %d", (
int) event);
2599 return gettext_noop(
"Junk view columns are not updatable.");
2604 return gettext_noop(
"View columns that are not columns of their base relation are not updatable.");
2607 return gettext_noop(
"View columns that refer to system columns are not updatable.");
2610 return gettext_noop(
"View columns that return whole-row references are not updatable.");
2671 return gettext_noop(
"Views containing DISTINCT are not automatically updatable.");
2674 return gettext_noop(
"Views containing GROUP BY are not automatically updatable.");
2677 return gettext_noop(
"Views containing HAVING are not automatically updatable.");
2680 return gettext_noop(
"Views containing UNION, INTERSECT, or EXCEPT are not automatically updatable.");
2683 return gettext_noop(
"Views containing WITH are not automatically updatable.");
2686 return gettext_noop(
"Views containing LIMIT or OFFSET are not automatically updatable.");
2697 if (viewquery->hasAggs)
2698 return gettext_noop(
"Views that return aggregate functions are not automatically updatable.");
2700 if (viewquery->hasWindowFuncs)
2701 return gettext_noop(
"Views that return window functions are not automatically updatable.");
2703 if (viewquery->hasTargetSRFs)
2704 return gettext_noop(
"Views that return set-returning functions are not automatically updatable.");
2711 return gettext_noop(
"Views that do not select from a single table or view are not automatically updatable.");
2715 return gettext_noop(
"Views that do not select from a single table or view are not automatically updatable.");
2719 (base_rte->relkind != RELKIND_RELATION &&
2720 base_rte->relkind != RELKIND_FOREIGN_TABLE &&
2721 base_rte->relkind != RELKIND_VIEW &&
2722 base_rte->relkind != RELKIND_PARTITIONED_TABLE))
2723 return gettext_noop(
"Views that do not select from a single table or view are not automatically updatable.");
2726 return gettext_noop(
"Views containing TABLESAMPLE are not automatically updatable.");
2750 return gettext_noop(
"Views that have no updatable columns are not automatically updatable.");
2784 char **non_updatable_col)
2798 if (updatable_cols != NULL)
2799 *updatable_cols = NULL;
2800 if (non_updatable_col != NULL)
2801 *non_updatable_col = NULL;
2808 const char *col_update_detail;
2813 if (col_update_detail == NULL)
2816 if (updatable_cols != NULL)
2822 if (non_updatable_col != NULL)
2823 *non_updatable_col = tle->resname;
2824 return col_update_detail;
2865 List *outer_reloids,
2866 bool include_triggers,
2873#define ALL_EVENTS ((1 << CMD_INSERT) | (1 << CMD_UPDATE) | (1 << CMD_DELETE))
2897 if (rel->
rd_rel->relkind == RELKIND_RELATION ||
2898 rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
2906 if (rulelocks != NULL)
2928 if (include_triggers)
2951 if (rel->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
2973 if (rel->
rd_rel->relkind == RELKIND_VIEW)
2992 &updatable_cols, NULL);
2994 if (include_cols != NULL)
3012 if (base_rte->relkind != RELKIND_RELATION &&
3013 base_rte->relkind != RELKIND_PARTITIONED_TABLE)
3015 baseoid = base_rte->relid;
3026 events |= auto_events;
3067 foreach(lc, targetlist)
3088 if (tle != NULL && !tle->resjunk &&
IsA(tle->
expr,
Var))
3096 elog(
ERROR,
"attribute number %d not found in view targetlist",
3121 List *mergeActionList,
3130 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3131 errmsg(
"cannot insert into view \"%s\"",
3134 errhint(
"To enable inserting into the view, provide an INSTEAD OF INSERT trigger or an unconditional ON INSERT DO INSTEAD rule."));
3138 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3139 errmsg(
"cannot update view \"%s\"",
3142 errhint(
"To enable updating the view, provide an INSTEAD OF UPDATE trigger or an unconditional ON UPDATE DO INSTEAD rule."));
3146 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3147 errmsg(
"cannot delete from view \"%s\"",
3150 errhint(
"To enable deleting from the view, provide an INSTEAD OF DELETE trigger or an unconditional ON DELETE DO INSTEAD rule."));
3160 switch (
action->commandType)
3165 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3166 errmsg(
"cannot insert into view \"%s\"",
3169 errhint(
"To enable inserting into the view using MERGE, provide an INSTEAD OF INSERT trigger."));
3174 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3175 errmsg(
"cannot update view \"%s\"",
3178 errhint(
"To enable updating the view using MERGE, provide an INSTEAD OF UPDATE trigger."));
3183 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3184 errmsg(
"cannot delete from view \"%s\"",
3187 errhint(
"To enable deleting from the view using MERGE, provide an INSTEAD OF DELETE trigger."));
3198 elog(
ERROR,
"unrecognized CmdType: %d", (
int) command);
3217 bool insert_or_update;
3218 const char *auto_update_detail;
3229 List *view_targetlist;
3242 view_rte =
rt_fetch(parsetree->resultRelation, parsetree->
rtable);
3261 insert_or_update =
true;
3271 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3272 errmsg(
"access to non-system view \"%s\" is restricted",
3281 auto_update_detail =
3284 if (auto_update_detail)
3288 auto_update_detail);
3294 if (insert_or_update)
3297 char *non_updatable_col;
3350 &non_updatable_col);
3351 if (auto_update_detail)
3361 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3362 errmsg(
"cannot insert into column \"%s\" of view \"%s\"",
3369 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3370 errmsg(
"cannot update column \"%s\" of view \"%s\"",
3377 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3378 errmsg(
"cannot merge into column \"%s\" of view \"%s\"",
3405 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3406 errmsg(
"cannot merge into view \"%s\"",
3408 errdetail(
"MERGE is not supported for views with INSTEAD OF triggers for some actions but not all."),
3409 errhint(
"To enable merging into the view, either provide a full set of INSTEAD OF triggers or drop the existing INSTEAD OF triggers."));
3438 base_rte->relkind = base_rel->
rd_rel->relkind;
3446 if (viewquery->hasSubLinks)
3477 new_rte->
inh =
false;
3513 new_rte->perminfoindex = 0;
3561 new_rte->securityQuals = view_rte->securityQuals;
3562 view_rte->securityQuals =
NIL;
3568 parsetree = (
Query *)
3570 parsetree->resultRelation,
3586 parsetree->resultRelation,
3589 Assert(parsetree->resultRelation == new_rt_index);
3612 if (view_tle != NULL && !view_tle->resjunk &&
IsA(view_tle->
expr,
Var))
3615 elog(
ERROR,
"attribute number %d not found in view targetlist",
3632 if (view_tle != NULL && !view_tle->resjunk &&
IsA(view_tle->
expr,
Var))
3633 tle->resno = ((
Var *) view_tle->
expr)->varattno;
3635 elog(
ERROR,
"attribute number %d not found in view targetlist",
3649 Index old_exclRelIndex,
3669 if (view_tle != NULL && !view_tle->resjunk &&
IsA(view_tle->
expr,
Var))
3672 elog(
ERROR,
"attribute number %d not found in view targetlist",
3691 new_exclRte = new_exclNSItem->
p_rte;
3692 new_exclRte->relkind = RELKIND_COMPOSITE_TYPE;
3694 new_exclRte->perminfoindex = 0;
3718 new_exclRelIndex, 0);
3729 &parsetree->hasSubLinks);
3769 new_rte->securityQuals =
lcons(viewqual, new_rte->securityQuals);
3780 if (!parsetree->hasSubLinks)
3793 if (insert_or_update)
3806 if (parsetree->withCheckOptions !=
NIL)
3827 if (has_wco && (cascaded || viewquery->
jointree->
quals != NULL))
3838 parsetree->withCheckOptions =
lcons(wco,
3839 parsetree->withCheckOptions);
3852 if (!parsetree->hasSubLinks &&
3880 bool instead =
false;
3881 bool returning =
false;
3882 bool updatableview =
false;
3883 Query *qual_product = NULL;
3892 foreach(lc1, parsetree->
cteList)
3923 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3924 errmsg(
"DO INSTEAD NOTIFY rules are not supported for data-modifying statements in WITH")));
3927 Assert(!ctequery->canSetTag);
3931 else if (newstuff ==
NIL)
3934 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3935 errmsg(
"DO INSTEAD NOTHING rules are not supported for data-modifying statements in WITH")));
3942 foreach(lc2, newstuff)
3948 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3949 errmsg(
"conditional DO INSTEAD rules are not supported for data-modifying statements in WITH")));
3952 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3953 errmsg(
"DO ALSO rules are not supported for data-modifying statements in WITH")));
3957 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3958 errmsg(
"multi-statement DO INSTEAD rules are not supported for data-modifying statements in WITH")));
3972 int result_relation;
3976 int product_orig_rt_length;
3977 List *product_queries;
3978 bool hasUpdate =
false;
3979 int values_rte_index = 0;
3980 bool defaults_remaining =
false;
3982 result_relation = parsetree->resultRelation;
3983 Assert(result_relation != 0);
4019 if (values_rte != NULL)
4020 elog(
ERROR,
"more than one VALUES RTE found");
4023 values_rte_index = rtr->
rtindex;
4030 Bitmapset *unused_values_attrnos = NULL;
4035 parsetree->override,
4039 &unused_values_attrnos);
4043 unused_values_attrnos))
4044 defaults_remaining =
true;
4052 parsetree->override,
4063 parsetree->override,
4074 parsetree->override,
4089 switch (
action->commandType)
4119 elog(
ERROR,
"unrecognized commandType: %d", (
int) event);
4125 result_relation, parsetree, &hasUpdate);
4144 if (defaults_remaining && product_queries !=
NIL)
4157 foreach(n, product_queries)
4183 elog(
ERROR,
"failed to find VALUES RTE in product query");
4205 rt_entry_relation->
rd_rel->relkind == RELKIND_VIEW &&
4214 if (qual_product != NULL)
4218 gettext_noop(
"Views with conditional DO INSTEAD rules are not automatically updatable."));
4234 product_queries =
lcons(parsetree, product_queries);
4236 product_queries =
lappend(product_queries, parsetree);
4247 updatableview =
true;
4254 if (product_queries !=
NIL)
4259 foreach(n, rewrite_events)
4263 rev->
event == event)
4265 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
4266 errmsg(
"infinite recursion detected in rules for relation \"%s\"",
4273 rewrite_events =
lappend(rewrite_events, rev);
4275 foreach(n, product_queries)
4292 product_orig_rt_length);
4306 if ((instead || qual_product != NULL) &&
4314 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4315 errmsg(
"cannot perform INSERT RETURNING on relation \"%s\"",
4317 errhint(
"You need an unconditional ON INSERT DO INSTEAD rule with a RETURNING clause.")));
4321 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4322 errmsg(
"cannot perform UPDATE RETURNING on relation \"%s\"",
4324 errhint(
"You need an unconditional ON UPDATE DO INSTEAD rule with a RETURNING clause.")));
4328 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4329 errmsg(
"cannot perform DELETE RETURNING on relation \"%s\"",
4331 errhint(
"You need an unconditional ON DELETE DO INSTEAD rule with a RETURNING clause.")));
4334 elog(
ERROR,
"unrecognized commandType: %d",
4345 (product_queries !=
NIL || hasUpdate) &&
4348 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4349 errmsg(
"INSERT with ON CONFLICT clause cannot be used with table that has INSERT or UPDATE rules")));
4370 if (qual_product != NULL)
4371 rewritten =
lcons(qual_product, rewritten);
4373 rewritten =
lcons(parsetree, rewritten);
4377 if (qual_product != NULL)
4378 rewritten =
lappend(rewritten, qual_product);
4380 rewritten =
lappend(rewritten, parsetree);
4396 foreach(lc1, rewritten)
4405 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4406 errmsg(
"WITH cannot be used in a query that is rewritten by rules into multiple queries")));
4439 for (
int i = 0;
i < tupdesc->
natts;
i++)
4443 if (attr->attgenerated == ATTRIBUTE_GENERATED_VIRTUAL)
4508 Assert(att_tup->attgenerated == ATTRIBUTE_GENERATED_VIRTUAL);
4511 if (defexpr == NULL)
4512 elog(
ERROR,
"no generation expression found for column number %d of table \"%s\"",
4520 attcollid = att_tup->attcollation;
4529 defexpr = (
Node *) ce;
4548 int64 input_query_id = parsetree->queryId;
4553 bool foundOriginalQuery;
4560 Assert(parsetree->canSetTag);
4577 foreach(l, querylist)
4583 query->queryId = input_query_id;
4585 results =
lappend(results, query);
4605 foundOriginalQuery =
false;
4614 Assert(query->canSetTag);
4615 Assert(!foundOriginalQuery);
4616 foundOriginalQuery =
true;
4617#ifndef USE_ASSERT_CHECKING
4623 Assert(!query->canSetTag);
4627 lastInstead = query;
4631 if (!foundOriginalQuery && lastInstead != NULL)
4632 lastInstead->canSetTag =
true;
#define InvalidAttrNumber
Bitmapset * bms_int_members(Bitmapset *a, const Bitmapset *b)
int bms_next_member(const Bitmapset *a, int prevbit)
Bitmapset * bms_del_member(Bitmapset *a, int x)
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)
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)
Assert(PointerIsAligned(start, uint64))
if(TABLE==NULL||TABLE_index==NULL)
List * lappend(List *list, void *datum)
List * list_concat(List *list1, const List *list2)
List * list_concat_copy(const List *list1, const List *list2)
List * lappend_oid(List *list, Oid datum)
List * lcons(void *datum, List *list)
List * list_delete_last(List *list)
bool list_member_oid(const List *list, Oid datum)
Node * get_typdefault(Oid typid)
Alias * makeAlias(const char *aliasname, List *colnames)
Const * makeNullConst(Oid consttype, int32 consttypmod, Oid constcollid)
Var * makeWholeRowVar(RangeTblEntry *rte, int varno, Index varlevelsup, bool allowScalar)
TargetEntry * makeTargetEntry(Expr *expr, AttrNumber resno, char *resname, bool resjunk)
TargetEntry * flatCopyTargetEntry(TargetEntry *src_tle)
char * pstrdup(const char *in)
void pfree(void *pointer)
void * palloc0(Size size)
Oid exprType(const Node *expr)
Oid exprCollation(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_null_to_domain(Oid typid, int32 typmod, Oid collation, int typlen, bool typbyval)
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)
ParseNamespaceItem * addRangeTableEntryForRelation(ParseState *pstate, Relation rel, int lockmode, Alias *alias, bool inh, bool inFromCl)
RTEPermissionInfo * getRTEPermissionInfo(List *rteperminfos, RangeTblEntry *rte)
RowMarkClause * get_parse_rowmark(Query *qry, Index rtindex)
TargetEntry * get_tle_by_resno(List *tlist, AttrNumber resno)
bool get_rte_attribute_is_dropped(RangeTblEntry *rte, AttrNumber attnum)
RTEPermissionInfo * addRTEPermissionInfo(List **rteperminfos, RangeTblEntry *rte)
#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
@ OVERRIDING_SYSTEM_VALUE
#define RelationGetRelid(relation)
#define RelationHasCheckOption(relation)
#define RelationHasSecurityInvoker(relation)
#define RelationGetDescr(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 * ApplyRetrieveRule(Query *parsetree, RewriteRule *rule, int rt_index, Relation relation, List *activeRIRs)
static Query * rewriteRuleAction(Query *parsetree, Query *rule_action, Node *rule_qual, int rt_index, CmdType event, bool *returning_flag)
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)
static const char * view_cols_are_auto_updatable(Query *viewquery, Bitmapset *required_cols, Bitmapset **updatable_cols, char **non_updatable_col)
struct fireRIRonSubLink_context fireRIRonSubLink_context
static List * fireRules(Query *parsetree, int rt_index, CmdType event, List *locks, bool *instead_flag, bool *returning_flag, Query **qual_product)
static Query * CopyAndAddInvertedQual(Query *parsetree, Node *rule_qual, int rt_index, CmdType event)
int relation_is_updatable(Oid reloid, List *outer_reloids, bool include_triggers, Bitmapset *include_cols)
Query * get_view_query(Relation view)
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 List * RewriteQuery(Query *parsetree, List *rewrite_events, int orig_rt_length)
static Bitmapset * adjust_view_column_set(Bitmapset *cols, List *targetlist)
const char * view_query_is_auto_updatable(Query *viewquery, bool check_cols)
struct acquireLocksOnSubLinks_context acquireLocksOnSubLinks_context
static const char * view_col_is_auto_updatable(RangeTblRef *rtr, TargetEntry *tle)
static bool searchForDefault(RangeTblEntry *rte)
struct rewrite_event rewrite_event
static Query * fireRIRrules(Query *parsetree, List *activeRIRs)
static Query * rewriteTargetView(Query *parsetree, Relation view)
List * QueryRewrite(Query *parsetree)
static Node * expand_generated_columns_internal(Node *node, Relation rel, int rt_index, RangeTblEntry *rte, int result_relation)
static Bitmapset * findDefaultOnlyColumns(RangeTblEntry *rte)
static void rewriteValuesRTEToNulls(Query *parsetree, RangeTblEntry *rte)
Node * build_generation_expression(Relation rel, int attrno)
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)
Node * build_column_default(Relation rel, int attrno)
static List * rewriteTargetListIU(List *targetList, CmdType commandType, OverridingKind override, Relation target_relation, RangeTblEntry *values_rte, int values_rte_index, Bitmapset **unused_values_attrnos)
Node * expand_generated_columns_in_expr(Node *node, Relation rel, int rt_index)
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)
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)
Query * getInsertSelectQuery(Query *parsetree, Query ***subquery_ptr)
void AddInvertedQual(Query *parsetree, Node *qual)
Node * ReplaceVarsFromTargetList(Node *node, int target_varno, int sublevels_up, RangeTblEntry *target_rte, List *targetlist, int result_relation, ReplaceVarsNoMatchOption nomatch_option, int nomatch_varno, bool *outer_hasSubLinks)
@ 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)
void check_stack_depth(void)
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
bool has_generated_virtual
#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)
static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)
String * makeString(char *str)
bool contain_vars_of_level(Node *node, int levelsup)
static struct rule * rules