68 bool *returning_flag);
79 const char *attrName);
90 int varno,
Query *parsetree,
bool *hasUpdate);
142 bool forUpdatePushedDown)
154 foreach(l, parsetree->
rtable)
180 else if (forUpdatePushedDown)
218 Var *aliasvar = aliasitem;
230 if (aliasvar &&
IsA(aliasvar,
Var))
242 if (aliasvar->
varno != curinputvarno)
244 curinputvarno = aliasvar->
varno;
245 if (curinputvarno >= rt_index)
246 elog(
ERROR,
"unexpected varno %d in JOIN RTE %d",
247 curinputvarno, rt_index);
248 curinputrte =
rt_fetch(curinputvarno,
258 newaliasvars =
lappend(newaliasvars, aliasitem);
271 (forUpdatePushedDown ||
293 if (parsetree->hasSubLinks)
348 bool *returning_flag)
354 Query **sub_action_ptr;
373 current_varno = rt_index;
403 foreach(lc, sub_action->
rtable)
441 List *perminfos_tail = sub_action->rteperminfos;
449 sub_action->rteperminfos =
copyObject(parsetree->rteperminfos);
451 rtable_tail, perminfos_tail);
458 if (parsetree->hasSubLinks && !sub_action->hasSubLinks)
460 foreach(lc, parsetree->
rtable)
467 sub_action->hasSubLinks =
471 sub_action->hasSubLinks =
475 sub_action->hasSubLinks =
479 sub_action->hasSubLinks =
486 sub_action->hasSubLinks |=
488 if (sub_action->hasSubLinks)
500 sub_action->hasRowSecurity |= parsetree->hasRowSecurity;
527 if (newjointree !=
NIL)
537 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
538 errmsg(
"conditional UNION/INTERSECT/EXCEPT statements are not implemented")));
547 if (parsetree->hasSubLinks && !sub_action->hasSubLinks)
548 sub_action->hasSubLinks =
570 foreach(lc, parsetree->
cteList)
575 foreach(lc2, sub_action->
cteList)
581 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
582 errmsg(
"WITH query name \"%s\" appears in both a rule action and the query being rewritten",
591 sub_action->hasRecursive |= parsetree->hasRecursive;
592 sub_action->hasModifyingCTE |= parsetree->hasModifyingCTE;
606 if (sub_action->hasModifyingCTE && rule_action != sub_action)
608 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
609 errmsg(
"INSERT ... SELECT rule actions are not supported for queries having data-modifying statements in WITH")));
617 AddQual(sub_action, rule_qual);
632 sub_action = (
Query *)
644 *sub_action_ptr = sub_action;
646 rule_action = sub_action;
661 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
662 errmsg(
"cannot have RETURNING lists in multiple rules")));
663 *returning_flag =
true;
666 parsetree->resultRelation,
673 &rule_action->hasSubLinks);
679 if (parsetree->hasSubLinks && !rule_action->hasSubLinks)
680 rule_action->hasSubLinks =
703 foreach(l, newjointree)
763 int values_rte_index,
787 next_junk_attrno = numattrs + 1;
789 foreach(temp, targetList)
793 if (!old_tle->resjunk)
796 attrno = old_tle->
resno;
797 if (attrno < 1 || attrno > numattrs)
798 elog(
ERROR,
"bogus resno %d in targetlist", attrno);
802 if (att_tup->attisdropped)
806 new_tles[attrno - 1] =
808 new_tles[attrno - 1],
823 if (old_tle->
resno != next_junk_attrno)
826 old_tle->
resno = next_junk_attrno;
828 junk_tlist =
lappend(junk_tlist, old_tle);
833 for (attrno = 1; attrno <= numattrs; attrno++)
841 if (att_tup->attisdropped)
849 apply_default = ((new_tle == NULL && commandType ==
CMD_INSERT) ||
854 int values_attrno = 0;
857 if (values_rte && new_tle &&
IsA(new_tle->
expr,
Var))
861 if (var->
varno == values_rte_index)
870 if (att_tup->attidentity == ATTRIBUTE_IDENTITY_ALWAYS && !apply_default)
873 apply_default =
true;
882 if (values_attrno != 0)
884 if (default_only_cols == NULL)
888 apply_default =
true;
893 (
errcode(ERRCODE_GENERATED_ALWAYS),
894 errmsg(
"cannot insert a non-DEFAULT value into column \"%s\"",
896 errdetail(
"Column \"%s\" is an identity column defined as GENERATED ALWAYS.",
898 errhint(
"Use OVERRIDING SYSTEM VALUE to override.")));
907 if (att_tup->attidentity == ATTRIBUTE_IDENTITY_BY_DEFAULT &&
909 apply_default =
true;
915 if (att_tup->attgenerated && !apply_default)
921 if (values_attrno != 0)
923 if (default_only_cols == NULL)
927 apply_default =
true;
932 (
errcode(ERRCODE_GENERATED_ALWAYS),
933 errmsg(
"cannot insert a non-DEFAULT value into column \"%s\"",
935 errdetail(
"Column \"%s\" is a generated column.",
944 if (values_attrno != 0 && apply_default && unused_values_attrnos)
956 if (att_tup->attidentity == ATTRIBUTE_IDENTITY_ALWAYS &&
957 new_tle && !apply_default)
959 (
errcode(ERRCODE_GENERATED_ALWAYS),
960 errmsg(
"column \"%s\" can only be updated to DEFAULT",
962 errdetail(
"Column \"%s\" is an identity column defined as GENERATED ALWAYS.",
965 if (att_tup->attgenerated && new_tle && !apply_default)
967 (
errcode(ERRCODE_GENERATED_ALWAYS),
968 errmsg(
"column \"%s\" can only be updated to DEFAULT",
970 errdetail(
"Column \"%s\" is a generated column.",
974 if (att_tup->attgenerated)
981 else if (apply_default)
1002 att_tup->attcollation,
1026 new_tlist =
lappend(new_tlist, new_tle);
1044 const char *attrName)
1055 if (prior_tle == NULL)
1095 prior_expr = (
Node *) prior_tle->
expr;
1110 if (src_input == NULL ||
1111 prior_input == NULL ||
1114 (
errcode(ERRCODE_SYNTAX_ERROR),
1115 errmsg(
"multiple assignments to same column \"%s\"",
1121 priorbottom = prior_input;
1126 if (newbottom == NULL)
1128 priorbottom = newbottom;
1130 if (!
equal(priorbottom, src_input))
1132 (
errcode(ERRCODE_SYNTAX_ERROR),
1133 errmsg(
"multiple assignments to same column \"%s\"",
1146 memcpy(fstore, prior_expr,
sizeof(
FieldStore));
1157 memcpy(fstore, src_expr,
sizeof(
FieldStore));
1158 fstore->
arg = (
Expr *) prior_expr;
1160 newexpr = (
Node *) fstore;
1168 newexpr = (
Node *) sbsref;
1182 newcoerce->
arg = (
Expr *) newexpr;
1183 newexpr = (
Node *) newcoerce;
1228 Oid atttype = att_tup->atttypid;
1229 int32 atttypmod = att_tup->atttypmod;
1233 if (att_tup->attidentity)
1242 if (rel->
rd_rel->relispartition)
1254 nve->
typeId = att_tup->atttypid;
1256 return (
Node *) nve;
1262 if (att_tup->atthasdef)
1266 elog(
ERROR,
"default expression not found for attribute %d of relation \"%s\"",
1274 if (expr == NULL && !att_tup->attgenerated)
1297 (
errcode(ERRCODE_DATATYPE_MISMATCH),
1298 errmsg(
"column \"%s\" is of type %s"
1299 " but default expression is of type %s",
1303 errhint(
"You will need to rewrite or cast the expression.")));
1320 foreach(lc2, sublist)
1348 if (default_only_cols == NULL)
1352 foreach(lc2, sublist)
1365 foreach(lc2, sublist)
1383 return default_only_cols;
1431 bool isAutoUpdatableView;
1456 attrnos = (
int *)
palloc0(numattrs *
sizeof(
int));
1470 Assert(attrno >= 1 && attrno <= numattrs);
1471 attrnos[attrno - 1] = tle->
resno;
1481 isAutoUpdatableView =
false;
1482 if (target_relation->
rd_rel->relkind == RELKIND_VIEW &&
1492 parsetree->resultRelation, parsetree, &hasUpdate);
1500 rule_lock->
qual == NULL)
1513 isAutoUpdatableView =
true;
1528 foreach(lc2, sublist)
1531 int attrno = attrnos[
i++];
1555 elog(
ERROR,
"cannot set value in column %d to DEFAULT",
i);
1556 Assert(attrno > 0 && attrno <= target_relation->rd_att->natts);
1559 if (!att_tup->attisdropped)
1571 if (isAutoUpdatableView)
1574 newList =
lappend(newList, col);
1575 allReplaced =
false;
1581 att_tup->attcollation,
1595 newList =
lappend(newList, new_expr);
1598 newList =
lappend(newList, col);
1600 newValues =
lappend(newValues, newList);
1632 foreach(lc2, sublist)
1645 newList =
lappend(newList, col);
1647 newValues =
lappend(newValues, newList);
1669 if (rulelocks == NULL)
1674 if (parsetree->resultRelation != varno)
1680 for (
i = 0;
i < nlocks;
i++)
1711 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1712 errmsg(
"cannot execute MERGE on relation \"%s\"",
1714 errdetail(
"MERGE is not supported for relations with rules."));
1717 if (oneLock->
event == event)
1721 matching_locks =
lappend(matching_locks, oneLock);
1725 return matching_locks;
1745 elog(
ERROR,
"expected just one rule action");
1746 if (
rule->qual != NULL)
1747 elog(
ERROR,
"cannot handle qualified ON SELECT rule");
1749 if (rt_index == parsetree->resultRelation)
1795 parsetree->resultRelation, 0);
1814 elog(
ERROR,
"unrecognized commandType: %d",
1924 strength, waitPolicy,
true);
1944 elog(
ERROR,
"unrecognized node type: %d",
1982 (
void *) activeRIRs);
1996 int origResultRelation = parsetree->resultRelation;
2006 foreach(lc, parsetree->
cteList)
2010 if (cte->search_clause || cte->cycle_clause)
2062 if (rte->
relkind == RELKIND_MATVIEW)
2083 if (rt_index != parsetree->resultRelation &&
2091 if (rt_index == parsetree->resultRelation &&
2092 rt_index != origResultRelation)
2108 for (
i = 0;
i <
rules->numLocks;
i++)
2126 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
2127 errmsg(
"infinite recursion detected in rules for relation \"%s\"",
2150 foreach(lc, parsetree->
cteList)
2162 if (parsetree->hasSubLinks)
2173 foreach(lc, parsetree->
rtable)
2177 List *securityQuals;
2178 List *withCheckOptions;
2179 bool hasRowSecurity;
2186 (rte->
relkind != RELKIND_RELATION &&
2187 rte->
relkind != RELKIND_PARTITIONED_TABLE))
2196 &securityQuals, &withCheckOptions,
2197 &hasRowSecurity, &hasSubLinks);
2199 if (securityQuals !=
NIL || withCheckOptions !=
NIL)
2211 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
2212 errmsg(
"infinite recursion detected in policy for relation \"%s\"",
2252 parsetree->withCheckOptions =
list_concat(withCheckOptions,
2253 parsetree->withCheckOptions);
2261 parsetree->hasRowSecurity =
true;
2263 parsetree->hasSubLinks =
true;
2319 &parsetree->hasSubLinks);
2361 bool *returning_flag,
2362 Query **qual_product)
2370 Node *event_qual = rule_lock->
qual;
2378 if (event_qual != NULL)
2383 *instead_flag =
true;
2405 if (*qual_product == NULL)
2423 event_qual, rt_index, event,
2426 rule_action->querySource = qsrc;
2427 rule_action->canSetTag =
false;
2429 results =
lappend(results, rule_action);
2461 elog(
ERROR,
"invalid _RETURN rule action specification");
2467 elog(
ERROR,
"failed to find _RETURN rule for view");
2507 switch (
action->commandType)
2531 elog(
ERROR,
"unrecognized CmdType: %d", (
int) event);
2564 return gettext_noop(
"Junk view columns are not updatable.");
2569 return gettext_noop(
"View columns that are not columns of their base relation are not updatable.");
2572 return gettext_noop(
"View columns that refer to system columns are not updatable.");
2575 return gettext_noop(
"View columns that return whole-row references are not updatable.");
2636 return gettext_noop(
"Views containing DISTINCT are not automatically updatable.");
2639 return gettext_noop(
"Views containing GROUP BY are not automatically updatable.");
2642 return gettext_noop(
"Views containing HAVING are not automatically updatable.");
2645 return gettext_noop(
"Views containing UNION, INTERSECT, or EXCEPT are not automatically updatable.");
2648 return gettext_noop(
"Views containing WITH are not automatically updatable.");
2651 return gettext_noop(
"Views containing LIMIT or OFFSET are not automatically updatable.");
2662 if (viewquery->hasAggs)
2663 return gettext_noop(
"Views that return aggregate functions are not automatically updatable.");
2665 if (viewquery->hasWindowFuncs)
2666 return gettext_noop(
"Views that return window functions are not automatically updatable.");
2668 if (viewquery->hasTargetSRFs)
2669 return gettext_noop(
"Views that return set-returning functions are not automatically updatable.");
2676 return gettext_noop(
"Views that do not select from a single table or view are not automatically updatable.");
2680 return gettext_noop(
"Views that do not select from a single table or view are not automatically updatable.");
2684 (base_rte->
relkind != RELKIND_RELATION &&
2685 base_rte->
relkind != RELKIND_FOREIGN_TABLE &&
2686 base_rte->
relkind != RELKIND_VIEW &&
2687 base_rte->
relkind != RELKIND_PARTITIONED_TABLE))
2688 return gettext_noop(
"Views that do not select from a single table or view are not automatically updatable.");
2691 return gettext_noop(
"Views containing TABLESAMPLE are not automatically updatable.");
2715 return gettext_noop(
"Views that have no updatable columns are not automatically updatable.");
2749 char **non_updatable_col)
2763 if (updatable_cols != NULL)
2764 *updatable_cols = NULL;
2765 if (non_updatable_col != NULL)
2766 *non_updatable_col = NULL;
2773 const char *col_update_detail;
2778 if (col_update_detail == NULL)
2781 if (updatable_cols != NULL)
2787 if (non_updatable_col != NULL)
2788 *non_updatable_col = tle->resname;
2789 return col_update_detail;
2830 List *outer_reloids,
2831 bool include_triggers,
2838 #define ALL_EVENTS ((1 << CMD_INSERT) | (1 << CMD_UPDATE) | (1 << CMD_DELETE))
2862 if (rel->
rd_rel->relkind == RELKIND_RELATION ||
2863 rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
2871 if (rulelocks != NULL)
2893 if (include_triggers)
2916 if (rel->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
2938 if (rel->
rd_rel->relkind == RELKIND_VIEW)
2957 &updatable_cols, NULL);
2959 if (include_cols != NULL)
2977 if (base_rte->
relkind != RELKIND_RELATION &&
2978 base_rte->
relkind != RELKIND_PARTITIONED_TABLE)
2980 baseoid = base_rte->
relid;
2991 events |= auto_events;
3032 foreach(lc, targetlist)
3053 if (tle != NULL && !tle->resjunk &&
IsA(tle->
expr,
Var))
3061 elog(
ERROR,
"attribute number %d not found in view targetlist",
3086 List *mergeActionList,
3095 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3096 errmsg(
"cannot insert into view \"%s\"",
3099 errhint(
"To enable inserting into the view, provide an INSTEAD OF INSERT trigger or an unconditional ON INSERT DO INSTEAD rule."));
3103 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3104 errmsg(
"cannot update view \"%s\"",
3107 errhint(
"To enable updating the view, provide an INSTEAD OF UPDATE trigger or an unconditional ON UPDATE DO INSTEAD rule."));
3111 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3112 errmsg(
"cannot delete from view \"%s\"",
3115 errhint(
"To enable deleting from the view, provide an INSTEAD OF DELETE trigger or an unconditional ON DELETE DO INSTEAD rule."));
3125 switch (
action->commandType)
3130 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3131 errmsg(
"cannot insert into view \"%s\"",
3134 errhint(
"To enable inserting into the view using MERGE, provide an INSTEAD OF INSERT trigger."));
3139 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3140 errmsg(
"cannot update view \"%s\"",
3143 errhint(
"To enable updating the view using MERGE, provide an INSTEAD OF UPDATE trigger."));
3148 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3149 errmsg(
"cannot delete from view \"%s\"",
3152 errhint(
"To enable deleting from the view using MERGE, provide an INSTEAD OF DELETE trigger."));
3163 elog(
ERROR,
"unrecognized CmdType: %d", (
int) command);
3182 bool insert_or_update;
3183 const char *auto_update_detail;
3194 List *view_targetlist;
3222 insert_or_update =
true;
3234 auto_update_detail =
3237 if (auto_update_detail)
3241 auto_update_detail);
3251 if (insert_or_update)
3254 char *non_updatable_col;
3294 &non_updatable_col);
3295 if (auto_update_detail)
3305 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3306 errmsg(
"cannot insert into column \"%s\" of view \"%s\"",
3313 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3314 errmsg(
"cannot update column \"%s\" of view \"%s\"",
3321 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3322 errmsg(
"cannot merge into column \"%s\" of view \"%s\"",
3349 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3350 errmsg(
"cannot merge into view \"%s\"",
3352 errdetail(
"MERGE is not supported for views with INSTEAD OF triggers for some actions, but not others."),
3353 errhint(
"To enable merging into the view, either provide a full set of INSTEAD OF triggers or drop the existing INSTEAD OF triggers."));
3358 view_rte =
rt_fetch(parsetree->resultRelation, parsetree->
rtable);
3393 if (viewquery->hasSubLinks)
3424 new_rte->
inh =
false;
3518 parsetree = (
Query *)
3520 parsetree->resultRelation,
3535 parsetree->resultRelation,
3538 Assert(parsetree->resultRelation == new_rt_index);
3561 if (view_tle != NULL && !view_tle->resjunk &&
IsA(view_tle->
expr,
Var))
3564 elog(
ERROR,
"attribute number %d not found in view targetlist",
3581 if (view_tle != NULL && !view_tle->resjunk &&
IsA(view_tle->
expr,
Var))
3582 tle->resno = ((
Var *) view_tle->
expr)->varattno;
3584 elog(
ERROR,
"attribute number %d not found in view targetlist",
3598 Index old_exclRelIndex,
3618 if (view_tle != NULL && !view_tle->resjunk &&
IsA(view_tle->
expr,
Var))
3621 elog(
ERROR,
"attribute number %d not found in view targetlist",
3640 new_exclRte = new_exclNSItem->
p_rte;
3641 new_exclRte->
relkind = RELKIND_COMPOSITE_TYPE;
3667 new_exclRelIndex, 0);
3677 &parsetree->hasSubLinks);
3728 if (!parsetree->hasSubLinks)
3741 if (insert_or_update)
3754 if (parsetree->withCheckOptions !=
NIL)
3775 if (has_wco && (cascaded || viewquery->
jointree->
quals != NULL))
3786 parsetree->withCheckOptions =
lcons(wco,
3787 parsetree->withCheckOptions);
3800 if (!parsetree->hasSubLinks &&
3828 bool instead =
false;
3829 bool returning =
false;
3830 bool updatableview =
false;
3831 Query *qual_product = NULL;
3840 foreach(lc1, parsetree->
cteList)
3871 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3872 errmsg(
"DO INSTEAD NOTIFY rules are not supported for data-modifying statements in WITH")));
3875 Assert(!ctequery->canSetTag);
3879 else if (newstuff ==
NIL)
3882 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3883 errmsg(
"DO INSTEAD NOTHING rules are not supported for data-modifying statements in WITH")));
3890 foreach(lc2, newstuff)
3896 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3897 errmsg(
"conditional DO INSTEAD rules are not supported for data-modifying statements in WITH")));
3900 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3901 errmsg(
"DO ALSO rules are not supported for data-modifying statements in WITH")));
3905 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3906 errmsg(
"multi-statement DO INSTEAD rules are not supported for data-modifying statements in WITH")));
3920 int result_relation;
3924 int product_orig_rt_length;
3925 List *product_queries;
3926 bool hasUpdate =
false;
3927 int values_rte_index = 0;
3928 bool defaults_remaining =
false;
3930 result_relation = parsetree->resultRelation;
3931 Assert(result_relation != 0);
3967 if (values_rte != NULL)
3968 elog(
ERROR,
"more than one VALUES RTE found");
3971 values_rte_index = rtr->
rtindex;
3978 Bitmapset *unused_values_attrnos = NULL;
3983 parsetree->override,
3987 &unused_values_attrnos);
3991 unused_values_attrnos))
3992 defaults_remaining =
true;
4000 parsetree->override,
4011 parsetree->override,
4022 parsetree->override,
4037 switch (
action->commandType)
4067 elog(
ERROR,
"unrecognized commandType: %d", (
int) event);
4073 result_relation, parsetree, &hasUpdate);
4092 if (defaults_remaining && product_queries !=
NIL)
4105 foreach(n, product_queries)
4131 elog(
ERROR,
"failed to find VALUES RTE in product query");
4153 rt_entry_relation->
rd_rel->relkind == RELKIND_VIEW &&
4162 if (qual_product != NULL)
4166 gettext_noop(
"Views with conditional DO INSTEAD rules are not automatically updatable."));
4182 product_queries =
lcons(parsetree, product_queries);
4184 product_queries =
lappend(product_queries, parsetree);
4195 updatableview =
true;
4202 if (product_queries !=
NIL)
4207 foreach(n, rewrite_events)
4211 rev->
event == event)
4213 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
4214 errmsg(
"infinite recursion detected in rules for relation \"%s\"",
4221 rewrite_events =
lappend(rewrite_events, rev);
4223 foreach(n, product_queries)
4240 product_orig_rt_length);
4254 if ((instead || qual_product != NULL) &&
4262 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4263 errmsg(
"cannot perform INSERT RETURNING on relation \"%s\"",
4265 errhint(
"You need an unconditional ON INSERT DO INSTEAD rule with a RETURNING clause.")));
4269 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4270 errmsg(
"cannot perform UPDATE RETURNING on relation \"%s\"",
4272 errhint(
"You need an unconditional ON UPDATE DO INSTEAD rule with a RETURNING clause.")));
4276 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4277 errmsg(
"cannot perform DELETE RETURNING on relation \"%s\"",
4279 errhint(
"You need an unconditional ON DELETE DO INSTEAD rule with a RETURNING clause.")));
4282 elog(
ERROR,
"unrecognized commandType: %d",
4293 (product_queries !=
NIL || hasUpdate) &&
4296 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4297 errmsg(
"INSERT with ON CONFLICT clause cannot be used with table that has INSERT or UPDATE rules")));
4318 if (qual_product != NULL)
4319 rewritten =
lcons(qual_product, rewritten);
4321 rewritten =
lcons(parsetree, rewritten);
4325 if (qual_product != NULL)
4326 rewritten =
lappend(rewritten, qual_product);
4328 rewritten =
lappend(rewritten, parsetree);
4344 foreach(lc1, rewritten)
4353 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4354 errmsg(
"WITH cannot be used in a query that is rewritten by rules into multiple queries")));
4373 uint64 input_query_id = parsetree->queryId;
4378 bool foundOriginalQuery;
4385 Assert(parsetree->canSetTag);
4402 foreach(l, querylist)
4408 query->queryId = input_query_id;
4410 results =
lappend(results, query);
4430 foundOriginalQuery =
false;
4439 Assert(query->canSetTag);
4440 Assert(!foundOriginalQuery);
4441 foundOriginalQuery =
true;
4442 #ifndef USE_ASSERT_CHECKING
4448 Assert(!query->canSetTag);
4452 lastInstead = query;
4456 if (!foundOriginalQuery && lastInstead != NULL)
4457 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_int_members(Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_del_member(Bitmapset *a, int x)
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)
Assert(fmt[strlen(fmt) - 1] !='\n')
List * lappend(List *list, void *datum)
List * lappend_oid(List *list, Oid datum)
void list_free(List *list)
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)
List * get_partition_ancestors(Oid relid)
FormData_pg_attribute * Form_pg_attribute
Oid getIdentitySequence(Oid relid, 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