forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitb8a1247
committed
Fix INSERT ON CONFLICT UPDATE through a view that isn't just SELECT *.
When expanding an updatable view that is an INSERT's target, the rewriterfailed to rewrite Vars in the ON CONFLICT UPDATE clause. This accidentallyworked if the view was just "SELECT * FROM ...", as the transformationwould be a no-op in that case. With more complicated view targetlists,this omission would often lead to "attribute ... has the wrong type" errorsor even crashes, as reported by Mario De Frutos Dieguez.Fix by adding code to rewriteTargetView to fix up the data structurecorrectly. The easiest way to update the exclRelTlist list is to rebuildit from scratch looking at the new target relation, so factor the codefor that out of transformOnConflictClause to make it sharable.In passing, avoid duplicate permissions checks against the EXCLUDEDpseudo-relation, and prevent useless view expansion of that relation'sdummy RTE. The latter is only known to happen (after this patch) in caseswhere the query would fail later due to not having any INSTEAD OF triggersfor the view. But by exactly that token, it would create an unintendedand very poorly tested state of the query data structure, so it seems likea good idea to prevent it from happening at all.This has been broken since ON CONFLICT was introduced, so back-patchto 9.5.Dean Rasheed, based on an earlier patch by Amit Langote;comment-kibitzing and back-patching by meDiscussion:https://postgr.es/m/CAFYwGJ0xfzy8jaK80hVN2eUWr6huce0RU8AgU04MGD00igqkTg@mail.gmail.com1 parent5a23c74 commitb8a1247
File tree
5 files changed
+514
-57
lines changed- src
- backend
- parser
- rewrite
- include/parser
- test/regress
- expected
- sql
5 files changed
+514
-57
lines changedLines changed: 81 additions & 55 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1022 | 1022 |
| |
1023 | 1023 |
| |
1024 | 1024 |
| |
1025 |
| - | |
1026 |
| - | |
1027 |
| - | |
1028 | 1025 |
| |
1029 | 1026 |
| |
1030 | 1027 |
| |
| |||
1033 | 1030 |
| |
1034 | 1031 |
| |
1035 | 1032 |
| |
1036 |
| - | |
| 1033 | + | |
1037 | 1034 |
| |
1038 |
| - | |
| 1035 | + | |
| 1036 | + | |
1039 | 1037 |
| |
1040 | 1038 |
| |
1041 | 1039 |
| |
1042 | 1040 |
| |
1043 | 1041 |
| |
1044 | 1042 |
| |
1045 |
| - | |
1046 |
| - | |
1047 |
| - | |
1048 |
| - | |
1049 |
| - | |
1050 |
| - | |
1051 |
| - | |
1052 |
| - | |
1053 |
| - | |
1054 |
| - | |
1055 |
| - | |
1056 |
| - | |
1057 |
| - | |
1058 |
| - | |
1059 |
| - | |
1060 |
| - | |
1061 |
| - | |
1062 |
| - | |
1063 |
| - | |
1064 |
| - | |
1065 |
| - | |
1066 |
| - | |
1067 |
| - | |
1068 |
| - | |
1069 |
| - | |
1070 |
| - | |
1071 |
| - | |
1072 |
| - | |
1073 |
| - | |
| 1043 | + | |
| 1044 | + | |
1074 | 1045 |
| |
1075 |
| - | |
1076 |
| - | |
1077 |
| - | |
1078 |
| - | |
1079 |
| - | |
1080 |
| - | |
1081 |
| - | |
1082 |
| - | |
| 1046 | + | |
1083 | 1047 |
| |
1084 |
| - | |
1085 |
| - | |
1086 |
| - | |
1087 |
| - | |
1088 |
| - | |
1089 |
| - | |
1090 |
| - | |
1091 |
| - | |
1092 |
| - | |
1093 |
| - | |
1094 |
| - | |
1095 |
| - | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
1096 | 1051 |
| |
1097 | 1052 |
| |
1098 | 1053 |
| |
1099 |
| - | |
| 1054 | + | |
1100 | 1055 |
| |
1101 | 1056 |
| |
1102 | 1057 |
| |
1103 | 1058 |
| |
1104 | 1059 |
| |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
1105 | 1063 |
| |
1106 | 1064 |
| |
1107 | 1065 |
| |
| |||
1126 | 1084 |
| |
1127 | 1085 |
| |
1128 | 1086 |
| |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
1129 | 1155 |
| |
1130 | 1156 |
| |
1131 | 1157 |
| |
|
Lines changed: 101 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
29 | 29 |
| |
30 | 30 |
| |
31 | 31 |
| |
| 32 | + | |
32 | 33 |
| |
33 | 34 |
| |
34 | 35 |
| |
| |||
1770 | 1771 |
| |
1771 | 1772 |
| |
1772 | 1773 |
| |
| 1774 | + | |
| 1775 | + | |
| 1776 | + | |
| 1777 | + | |
| 1778 | + | |
| 1779 | + | |
| 1780 | + | |
| 1781 | + | |
| 1782 | + | |
| 1783 | + | |
| 1784 | + | |
1773 | 1785 |
| |
1774 | 1786 |
| |
1775 | 1787 |
| |
| |||
2875 | 2887 |
| |
2876 | 2888 |
| |
2877 | 2889 |
| |
2878 |
| - | |
2879 |
| - | |
2880 | 2890 |
| |
2881 | 2891 |
| |
2882 | 2892 |
| |
| |||
3034 | 3044 |
| |
3035 | 3045 |
| |
3036 | 3046 |
| |
| 3047 | + | |
| 3048 | + | |
| 3049 | + | |
| 3050 | + | |
| 3051 | + | |
| 3052 | + | |
| 3053 | + | |
| 3054 | + | |
| 3055 | + | |
| 3056 | + | |
| 3057 | + | |
| 3058 | + | |
| 3059 | + | |
| 3060 | + | |
| 3061 | + | |
| 3062 | + | |
| 3063 | + | |
| 3064 | + | |
| 3065 | + | |
| 3066 | + | |
| 3067 | + | |
| 3068 | + | |
| 3069 | + | |
| 3070 | + | |
| 3071 | + | |
| 3072 | + | |
| 3073 | + | |
| 3074 | + | |
| 3075 | + | |
| 3076 | + | |
| 3077 | + | |
| 3078 | + | |
| 3079 | + | |
| 3080 | + | |
| 3081 | + | |
| 3082 | + | |
| 3083 | + | |
| 3084 | + | |
| 3085 | + | |
| 3086 | + | |
| 3087 | + | |
| 3088 | + | |
| 3089 | + | |
| 3090 | + | |
| 3091 | + | |
| 3092 | + | |
| 3093 | + | |
| 3094 | + | |
| 3095 | + | |
| 3096 | + | |
| 3097 | + | |
| 3098 | + | |
| 3099 | + | |
| 3100 | + | |
| 3101 | + | |
| 3102 | + | |
| 3103 | + | |
| 3104 | + | |
| 3105 | + | |
| 3106 | + | |
| 3107 | + | |
| 3108 | + | |
| 3109 | + | |
| 3110 | + | |
| 3111 | + | |
| 3112 | + | |
| 3113 | + | |
| 3114 | + | |
| 3115 | + | |
| 3116 | + | |
| 3117 | + | |
| 3118 | + | |
| 3119 | + | |
| 3120 | + | |
| 3121 | + | |
| 3122 | + | |
| 3123 | + | |
| 3124 | + | |
| 3125 | + | |
| 3126 | + | |
| 3127 | + | |
| 3128 | + | |
| 3129 | + | |
| 3130 | + | |
| 3131 | + | |
| 3132 | + | |
| 3133 | + | |
3037 | 3134 |
| |
3038 | 3135 |
| |
3039 | 3136 |
| |
| |||
3161 | 3258 |
| |
3162 | 3259 |
| |
3163 | 3260 |
| |
| 3261 | + | |
| 3262 | + | |
3164 | 3263 |
| |
3165 | 3264 |
| |
3166 | 3265 |
| |
|
Lines changed: 3 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
43 | 43 |
| |
44 | 44 |
| |
45 | 45 |
| |
| 46 | + | |
| 47 | + | |
| 48 | + | |
46 | 49 |
|
0 commit comments
Comments
(0)