67 bool *returning_flag);
78 const char *attrName);
89 int varno,
Query *parsetree,
bool *hasUpdate);
141 bool forUpdatePushedDown)
147 context.for_execute = forExecute;
153 foreach(l, parsetree->
rtable)
179 else if (forUpdatePushedDown)
184 lockmode = rte->rellockmode;
187 lockmode = rte->rellockmode;
195 rte->relkind = rel->
rd_rel->relkind;
214 foreach(ll, rte->joinaliasvars)
217 Var *aliasvar = aliasitem;
229 if (aliasvar &&
IsA(aliasvar,
Var))
241 if (aliasvar->
varno != curinputvarno)
243 curinputvarno = aliasvar->
varno;
244 if (curinputvarno >= rt_index)
245 elog(
ERROR,
"unexpected varno %d in JOIN RTE %d",
246 curinputvarno, rt_index);
247 curinputrte =
rt_fetch(curinputvarno,
257 newaliasvars =
lappend(newaliasvars, aliasitem);
259 rte->joinaliasvars = newaliasvars;
270 (forUpdatePushedDown ||
292 if (parsetree->hasSubLinks)
347 bool *returning_flag)
353 Query **sub_action_ptr;
372 current_varno = rt_index;
402 foreach(lc, sub_action->
rtable)
440 List *perminfos_tail = sub_action->rteperminfos;
448 sub_action->rteperminfos =
copyObject(parsetree->rteperminfos);
450 rtable_tail, perminfos_tail);
457 if (parsetree->hasSubLinks && !sub_action->hasSubLinks)
459 foreach(lc, parsetree->
rtable)
466 sub_action->hasSubLinks =
470 sub_action->hasSubLinks =
474 sub_action->hasSubLinks =
478 sub_action->hasSubLinks =
485 sub_action->hasSubLinks |=
487 if (sub_action->hasSubLinks)
499 sub_action->hasRowSecurity |= parsetree->hasRowSecurity;
526 if (newjointree !=
NIL)
536 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
537 errmsg(
"conditional UNION/INTERSECT/EXCEPT statements are not implemented")));
546 if (parsetree->hasSubLinks && !sub_action->hasSubLinks)
547 sub_action->hasSubLinks =
569 foreach(lc, parsetree->
cteList)
574 foreach(lc2, sub_action->
cteList)
580 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
581 errmsg(
"WITH query name \"%s\" appears in both a rule action and the query being rewritten",
590 sub_action->hasRecursive |= parsetree->hasRecursive;
591 sub_action->hasModifyingCTE |= parsetree->hasModifyingCTE;
605 if (sub_action->hasModifyingCTE && rule_action != sub_action)
607 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
608 errmsg(
"INSERT ... SELECT rule actions are not supported for queries having data-modifying statements in WITH")));
616 AddQual(sub_action, rule_qual);
631 sub_action = (
Query *)
643 *sub_action_ptr = sub_action;
645 rule_action = sub_action;
660 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
661 errmsg(
"cannot have RETURNING lists in multiple rules")));
662 *returning_flag =
true;
665 parsetree->resultRelation,
672 &rule_action->hasSubLinks);
678 if (parsetree->hasSubLinks && !rule_action->hasSubLinks)
679 rule_action->hasSubLinks =
702 foreach(l, newjointree)
762 int values_rte_index,
786 next_junk_attrno = numattrs + 1;
788 foreach(temp, targetList)
792 if (!old_tle->resjunk)
795 attrno = old_tle->
resno;
796 if (attrno < 1 || attrno > numattrs)
797 elog(
ERROR,
"bogus resno %d in targetlist", attrno);
801 if (att_tup->attisdropped)
805 new_tles[attrno - 1] =
807 new_tles[attrno - 1],
822 if (old_tle->
resno != next_junk_attrno)
825 old_tle->
resno = next_junk_attrno;
827 junk_tlist =
lappend(junk_tlist, old_tle);
832 for (attrno = 1; attrno <= numattrs; attrno++)
840 if (att_tup->attisdropped)
848 apply_default = ((new_tle == NULL && commandType ==
CMD_INSERT) ||
853 int values_attrno = 0;
856 if (values_rte && new_tle &&
IsA(new_tle->
expr,
Var))
860 if (var->
varno == values_rte_index)
869 if (att_tup->attidentity == ATTRIBUTE_IDENTITY_ALWAYS && !apply_default)
872 apply_default =
true;
881 if (values_attrno != 0)
883 if (default_only_cols == NULL)
887 apply_default =
true;
892 (
errcode(ERRCODE_GENERATED_ALWAYS),
893 errmsg(
"cannot insert a non-DEFAULT value into column \"%s\"",
895 errdetail(
"Column \"%s\" is an identity column defined as GENERATED ALWAYS.",
897 errhint(
"Use OVERRIDING SYSTEM VALUE to override.")));
906 if (att_tup->attidentity == ATTRIBUTE_IDENTITY_BY_DEFAULT &&
908 apply_default =
true;
914 if (att_tup->attgenerated && !apply_default)
920 if (values_attrno != 0)
922 if (default_only_cols == NULL)
926 apply_default =
true;
931 (
errcode(ERRCODE_GENERATED_ALWAYS),
932 errmsg(
"cannot insert a non-DEFAULT value into column \"%s\"",
934 errdetail(
"Column \"%s\" is a generated column.",
943 if (values_attrno != 0 && apply_default && unused_values_attrnos)
955 if (att_tup->attidentity == ATTRIBUTE_IDENTITY_ALWAYS &&
956 new_tle && !apply_default)
958 (
errcode(ERRCODE_GENERATED_ALWAYS),
959 errmsg(
"column \"%s\" can only be updated to DEFAULT",
961 errdetail(
"Column \"%s\" is an identity column defined as GENERATED ALWAYS.",
964 if (att_tup->attgenerated && new_tle && !apply_default)
966 (
errcode(ERRCODE_GENERATED_ALWAYS),
967 errmsg(
"column \"%s\" can only be updated to DEFAULT",
969 errdetail(
"Column \"%s\" is a generated column.",
973 if (att_tup->attgenerated)
980 else if (apply_default)
1001 att_tup->attcollation,
1025 new_tlist =
lappend(new_tlist, new_tle);
1043 const char *attrName)
1054 if (prior_tle == NULL)
1094 prior_expr = (
Node *) prior_tle->
expr;
1109 if (src_input == NULL ||
1110 prior_input == NULL ||
1113 (
errcode(ERRCODE_SYNTAX_ERROR),
1114 errmsg(
"multiple assignments to same column \"%s\"",
1120 priorbottom = prior_input;
1125 if (newbottom == NULL)
1127 priorbottom = newbottom;
1129 if (!
equal(priorbottom, src_input))
1131 (
errcode(ERRCODE_SYNTAX_ERROR),
1132 errmsg(
"multiple assignments to same column \"%s\"",
1145 memcpy(fstore, prior_expr,
sizeof(
FieldStore));
1156 memcpy(fstore, src_expr,
sizeof(
FieldStore));
1157 fstore->
arg = (
Expr *) prior_expr;
1159 newexpr = (
Node *) fstore;
1167 newexpr = (
Node *) sbsref;
1181 newcoerce->
arg = (
Expr *) newexpr;
1182 newexpr = (
Node *) newcoerce;
1227 Oid atttype = att_tup->atttypid;
1228 int32 atttypmod = att_tup->atttypmod;
1232 if (att_tup->attidentity)
1237 nve->
typeId = att_tup->atttypid;
1239 return (
Node *) nve;
1245 if (att_tup->atthasdef)
1249 elog(
ERROR,
"default expression not found for attribute %d of relation \"%s\"",
1257 if (expr == NULL && !att_tup->attgenerated)
1280 (
errcode(ERRCODE_DATATYPE_MISMATCH),
1281 errmsg(
"column \"%s\" is of type %s"
1282 " but default expression is of type %s",
1286 errhint(
"You will need to rewrite or cast the expression.")));
1303 foreach(lc2, sublist)
1331 if (default_only_cols == NULL)
1335 foreach(lc2, sublist)
1348 foreach(lc2, sublist)
1366 return default_only_cols;
1414 bool isAutoUpdatableView;
1439 attrnos = (
int *)
palloc0(numattrs *
sizeof(
int));
1453 Assert(attrno >= 1 && attrno <= numattrs);
1454 attrnos[attrno - 1] = tle->
resno;
1464 isAutoUpdatableView =
false;
1465 if (target_relation->
rd_rel->relkind == RELKIND_VIEW &&
1475 parsetree->resultRelation, parsetree, &hasUpdate);
1483 rule_lock->
qual == NULL)
1496 isAutoUpdatableView =
true;
1511 foreach(lc2, sublist)
1514 int attrno = attrnos[
i++];
1538 elog(
ERROR,
"cannot set value in column %d to DEFAULT",
i);
1539 Assert(attrno > 0 && attrno <= target_relation->rd_att->natts);
1542 if (!att_tup->attisdropped)
1554 if (isAutoUpdatableView)
1557 newList =
lappend(newList, col);
1558 allReplaced =
false;
1564 att_tup->attcollation,
1578 newList =
lappend(newList, new_expr);
1581 newList =
lappend(newList, col);
1583 newValues =
lappend(newValues, newList);
1615 foreach(lc2, sublist)
1628 newList =
lappend(newList, col);
1630 newValues =
lappend(newValues, newList);
1652 if (rulelocks == NULL)
1657 if (parsetree->resultRelation != varno)
1663 for (
i = 0;
i < nlocks;
i++)
1694 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1695 errmsg(
"cannot execute MERGE on relation \"%s\"",
1697 errdetail(
"MERGE is not supported for relations with rules."));
1700 if (oneLock->
event == event)
1704 matching_locks =
lappend(matching_locks, oneLock);
1708 return matching_locks;
1728 elog(
ERROR,
"expected just one rule action");
1729 if (
rule->qual != NULL)
1730 elog(
ERROR,
"cannot handle qualified ON SELECT rule");
1732 if (rt_index == parsetree->resultRelation)
1778 parsetree->resultRelation, 0);
1797 elog(
ERROR,
"unrecognized commandType: %d",
1860 while (
list_length(rte->eref->colnames) < numCols)
1862 rte->eref->colnames =
lappend(rte->eref->colnames,
1907 strength, waitPolicy,
true);
1927 elog(
ERROR,
"unrecognized node type: %d",
1965 (
void *) activeRIRs);
1979 int origResultRelation = parsetree->resultRelation;
1989 foreach(lc, parsetree->
cteList)
1993 if (cte->search_clause || cte->cycle_clause)
2045 if (rte->relkind == RELKIND_MATVIEW)
2066 if (rt_index != parsetree->resultRelation &&
2074 if (rt_index == parsetree->resultRelation &&
2075 rt_index != origResultRelation)
2091 for (
i = 0;
i <
rules->numLocks;
i++)
2109 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
2110 errmsg(
"infinite recursion detected in rules for relation \"%s\"",
2133 foreach(lc, parsetree->
cteList)
2145 if (parsetree->hasSubLinks)
2156 foreach(lc, parsetree->
rtable)
2160 List *securityQuals;
2161 List *withCheckOptions;
2162 bool hasRowSecurity;
2169 (rte->relkind != RELKIND_RELATION &&
2170 rte->relkind != RELKIND_PARTITIONED_TABLE))
2179 &securityQuals, &withCheckOptions,
2180 &hasRowSecurity, &hasSubLinks);
2182 if (securityQuals !=
NIL || withCheckOptions !=
NIL)
2194 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
2195 errmsg(
"infinite recursion detected in policy for relation \"%s\"",
2233 rte->securityQuals);
2235 parsetree->withCheckOptions =
list_concat(withCheckOptions,
2236 parsetree->withCheckOptions);
2244 parsetree->hasRowSecurity =
true;
2246 parsetree->hasSubLinks =
true;
2302 &parsetree->hasSubLinks);
2344 bool *returning_flag,
2345 Query **qual_product)
2353 Node *event_qual = rule_lock->
qual;
2361 if (event_qual != NULL)
2366 *instead_flag =
true;
2388 if (*qual_product == NULL)
2406 event_qual, rt_index, event,
2409 rule_action->querySource = qsrc;
2410 rule_action->canSetTag =
false;
2412 results =
lappend(results, rule_action);
2444 elog(
ERROR,
"invalid _RETURN rule action specification");
2450 elog(
ERROR,
"failed to find _RETURN rule for view");
2490 switch (
action->commandType)
2514 elog(
ERROR,
"unrecognized CmdType: %d", (
int) event);
2547 return gettext_noop(
"Junk view columns are not updatable.");
2552 return gettext_noop(
"View columns that are not columns of their base relation are not updatable.");
2555 return gettext_noop(
"View columns that refer to system columns are not updatable.");
2558 return gettext_noop(
"View columns that return whole-row references are not updatable.");
2619 return gettext_noop(
"Views containing DISTINCT are not automatically updatable.");
2622 return gettext_noop(
"Views containing GROUP BY are not automatically updatable.");
2625 return gettext_noop(
"Views containing HAVING are not automatically updatable.");
2628 return gettext_noop(
"Views containing UNION, INTERSECT, or EXCEPT are not automatically updatable.");
2631 return gettext_noop(
"Views containing WITH are not automatically updatable.");
2634 return gettext_noop(
"Views containing LIMIT or OFFSET are not automatically updatable.");
2645 if (viewquery->hasAggs)
2646 return gettext_noop(
"Views that return aggregate functions are not automatically updatable.");
2648 if (viewquery->hasWindowFuncs)
2649 return gettext_noop(
"Views that return window functions are not automatically updatable.");
2651 if (viewquery->hasTargetSRFs)
2652 return gettext_noop(
"Views that return set-returning functions are not automatically updatable.");
2659 return gettext_noop(
"Views that do not select from a single table or view are not automatically updatable.");
2663 return gettext_noop(
"Views that do not select from a single table or view are not automatically updatable.");
2667 (base_rte->relkind != RELKIND_RELATION &&
2668 base_rte->relkind != RELKIND_FOREIGN_TABLE &&
2669 base_rte->relkind != RELKIND_VIEW &&
2670 base_rte->relkind != RELKIND_PARTITIONED_TABLE))
2671 return gettext_noop(
"Views that do not select from a single table or view are not automatically updatable.");
2674 return gettext_noop(
"Views containing TABLESAMPLE are not automatically updatable.");
2698 return gettext_noop(
"Views that have no updatable columns are not automatically updatable.");
2732 char **non_updatable_col)
2746 if (updatable_cols != NULL)
2747 *updatable_cols = NULL;
2748 if (non_updatable_col != NULL)
2749 *non_updatable_col = NULL;
2756 const char *col_update_detail;
2761 if (col_update_detail == NULL)
2764 if (updatable_cols != NULL)
2770 if (non_updatable_col != NULL)
2771 *non_updatable_col = tle->resname;
2772 return col_update_detail;
2813 List *outer_reloids,
2814 bool include_triggers,
2821 #define ALL_EVENTS ((1 << CMD_INSERT) | (1 << CMD_UPDATE) | (1 << CMD_DELETE))
2845 if (rel->
rd_rel->relkind == RELKIND_RELATION ||
2846 rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
2854 if (rulelocks != NULL)
2876 if (include_triggers)
2899 if (rel->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
2921 if (rel->
rd_rel->relkind == RELKIND_VIEW)
2940 &updatable_cols, NULL);
2942 if (include_cols != NULL)
2960 if (base_rte->relkind != RELKIND_RELATION &&
2961 base_rte->relkind != RELKIND_PARTITIONED_TABLE)
2963 baseoid = base_rte->
relid;
2974 events |= auto_events;
3015 foreach(lc, targetlist)
3036 if (tle != NULL && !tle->resjunk &&
IsA(tle->
expr,
Var))
3044 elog(
ERROR,
"attribute number %d not found in view targetlist",
3069 List *mergeActionList,
3078 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3079 errmsg(
"cannot insert into view \"%s\"",
3082 errhint(
"To enable inserting into the view, provide an INSTEAD OF INSERT trigger or an unconditional ON INSERT DO INSTEAD rule."));
3086 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3087 errmsg(
"cannot update view \"%s\"",
3090 errhint(
"To enable updating the view, provide an INSTEAD OF UPDATE trigger or an unconditional ON UPDATE DO INSTEAD rule."));
3094 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3095 errmsg(
"cannot delete from view \"%s\"",
3098 errhint(
"To enable deleting from the view, provide an INSTEAD OF DELETE trigger or an unconditional ON DELETE DO INSTEAD rule."));
3108 switch (
action->commandType)
3113 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3114 errmsg(
"cannot insert into view \"%s\"",
3117 errhint(
"To enable inserting into the view using MERGE, provide an INSTEAD OF INSERT trigger."));
3122 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3123 errmsg(
"cannot update view \"%s\"",
3126 errhint(
"To enable updating the view using MERGE, provide an INSTEAD OF UPDATE trigger."));
3131 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3132 errmsg(
"cannot delete from view \"%s\"",
3135 errhint(
"To enable deleting from the view using MERGE, provide an INSTEAD OF DELETE trigger."));
3146 elog(
ERROR,
"unrecognized CmdType: %d", (
int) command);
3165 bool insert_or_update;
3166 const char *auto_update_detail;
3177 List *view_targetlist;
3190 view_rte =
rt_fetch(parsetree->resultRelation, parsetree->
rtable);
3209 insert_or_update =
true;
3221 auto_update_detail =
3224 if (auto_update_detail)
3228 auto_update_detail);
3234 if (insert_or_update)
3237 char *non_updatable_col;
3290 &non_updatable_col);
3291 if (auto_update_detail)
3301 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3302 errmsg(
"cannot insert into column \"%s\" of view \"%s\"",
3309 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3310 errmsg(
"cannot update column \"%s\" of view \"%s\"",
3317 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3318 errmsg(
"cannot merge into column \"%s\" of view \"%s\"",
3345 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3346 errmsg(
"cannot merge into view \"%s\"",
3348 errdetail(
"MERGE is not supported for views with INSTEAD OF triggers for some actions, but not others."),
3349 errhint(
"To enable merging into the view, either provide a full set of INSTEAD OF triggers or drop the existing INSTEAD OF triggers."));
3378 base_rte->relkind = base_rel->
rd_rel->relkind;
3386 if (viewquery->hasSubLinks)
3417 new_rte->
inh =
false;
3453 new_rte->perminfoindex = 0;
3501 new_rte->securityQuals = view_rte->securityQuals;
3502 view_rte->securityQuals =
NIL;
3508 parsetree = (
Query *)
3510 parsetree->resultRelation,
3525 parsetree->resultRelation,
3528 Assert(parsetree->resultRelation == new_rt_index);
3551 if (view_tle != NULL && !view_tle->resjunk &&
IsA(view_tle->
expr,
Var))
3554 elog(
ERROR,
"attribute number %d not found in view targetlist",
3571 if (view_tle != NULL && !view_tle->resjunk &&
IsA(view_tle->
expr,
Var))
3572 tle->resno = ((
Var *) view_tle->
expr)->varattno;
3574 elog(
ERROR,
"attribute number %d not found in view targetlist",
3588 Index old_exclRelIndex,
3608 if (view_tle != NULL && !view_tle->resjunk &&
IsA(view_tle->
expr,
Var))
3611 elog(
ERROR,
"attribute number %d not found in view targetlist",
3630 new_exclRte = new_exclNSItem->
p_rte;
3631 new_exclRte->relkind = RELKIND_COMPOSITE_TYPE;
3633 new_exclRte->perminfoindex = 0;
3657 new_exclRelIndex, 0);
3667 &parsetree->hasSubLinks);
3707 new_rte->securityQuals =
lcons(viewqual, new_rte->securityQuals);
3718 if (!parsetree->hasSubLinks)
3731 if (insert_or_update)
3744 if (parsetree->withCheckOptions !=
NIL)
3765 if (has_wco && (cascaded || viewquery->
jointree->
quals != NULL))
3776 parsetree->withCheckOptions =
lcons(wco,
3777 parsetree->withCheckOptions);
3790 if (!parsetree->hasSubLinks &&
3818 bool instead =
false;
3819 bool returning =
false;
3820 bool updatableview =
false;
3821 Query *qual_product = NULL;
3830 foreach(lc1, parsetree->
cteList)
3861 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3862 errmsg(
"DO INSTEAD NOTIFY rules are not supported for data-modifying statements in WITH")));
3865 Assert(!ctequery->canSetTag);
3869 else if (newstuff ==
NIL)
3872 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3873 errmsg(
"DO INSTEAD NOTHING rules are not supported for data-modifying statements in WITH")));
3880 foreach(lc2, newstuff)
3886 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3887 errmsg(
"conditional DO INSTEAD rules are not supported for data-modifying statements in WITH")));
3890 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3891 errmsg(
"DO ALSO rules are not supported for data-modifying statements in WITH")));
3895 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3896 errmsg(
"multi-statement DO INSTEAD rules are not supported for data-modifying statements in WITH")));
3910 int result_relation;
3914 int product_orig_rt_length;
3915 List *product_queries;
3916 bool hasUpdate =
false;
3917 int values_rte_index = 0;
3918 bool defaults_remaining =
false;
3920 result_relation = parsetree->resultRelation;
3921 Assert(result_relation != 0);
3957 if (values_rte != NULL)
3958 elog(
ERROR,
"more than one VALUES RTE found");
3961 values_rte_index = rtr->
rtindex;
3968 Bitmapset *unused_values_attrnos = NULL;
3973 parsetree->override,
3977 &unused_values_attrnos);
3981 unused_values_attrnos))
3982 defaults_remaining =
true;
3990 parsetree->override,
4001 parsetree->override,
4012 parsetree->override,
4027 switch (
action->commandType)
4057 elog(
ERROR,
"unrecognized commandType: %d", (
int) event);
4063 result_relation, parsetree, &hasUpdate);
4082 if (defaults_remaining && product_queries !=
NIL)
4095 foreach(n, product_queries)
4121 elog(
ERROR,
"failed to find VALUES RTE in product query");
4143 rt_entry_relation->
rd_rel->relkind == RELKIND_VIEW &&
4152 if (qual_product != NULL)
4156 gettext_noop(
"Views with conditional DO INSTEAD rules are not automatically updatable."));
4172 product_queries =
lcons(parsetree, product_queries);
4174 product_queries =
lappend(product_queries, parsetree);
4185 updatableview =
true;
4192 if (product_queries !=
NIL)
4197 foreach(n, rewrite_events)
4201 rev->
event == event)
4203 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
4204 errmsg(
"infinite recursion detected in rules for relation \"%s\"",
4211 rewrite_events =
lappend(rewrite_events, rev);
4213 foreach(n, product_queries)
4230 product_orig_rt_length);
4244 if ((instead || qual_product != NULL) &&
4252 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4253 errmsg(
"cannot perform INSERT RETURNING on relation \"%s\"",
4255 errhint(
"You need an unconditional ON INSERT DO INSTEAD rule with a RETURNING clause.")));
4259 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4260 errmsg(
"cannot perform UPDATE RETURNING on relation \"%s\"",
4262 errhint(
"You need an unconditional ON UPDATE DO INSTEAD rule with a RETURNING clause.")));
4266 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4267 errmsg(
"cannot perform DELETE RETURNING on relation \"%s\"",
4269 errhint(
"You need an unconditional ON DELETE DO INSTEAD rule with a RETURNING clause.")));
4272 elog(
ERROR,
"unrecognized commandType: %d",
4283 (product_queries !=
NIL || hasUpdate) &&
4286 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4287 errmsg(
"INSERT with ON CONFLICT clause cannot be used with table that has INSERT or UPDATE rules")));
4308 if (qual_product != NULL)
4309 rewritten =
lcons(qual_product, rewritten);
4311 rewritten =
lcons(parsetree, rewritten);
4315 if (qual_product != NULL)
4316 rewritten =
lappend(rewritten, qual_product);
4318 rewritten =
lappend(rewritten, parsetree);
4334 foreach(lc1, rewritten)
4343 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4344 errmsg(
"WITH cannot be used in a query that is rewritten by rules into multiple queries")));
4363 uint64 input_query_id = parsetree->queryId;
4368 bool foundOriginalQuery;
4375 Assert(parsetree->canSetTag);
4392 foreach(l, querylist)
4398 query->queryId = input_query_id;
4400 results =
lappend(results, query);
4420 foundOriginalQuery =
false;
4429 Assert(query->canSetTag);
4430 Assert(!foundOriginalQuery);
4431 foundOriginalQuery =
true;
4432 #ifndef USE_ASSERT_CHECKING
4438 Assert(!query->canSetTag);
4442 lastInstead = query;
4446 if (!foundOriginalQuery && lastInstead != NULL)
4447 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)
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)
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