- Notifications
You must be signed in to change notification settings - Fork4.9k
Commitc6b3c93
committed
Make operator precedence follow the SQL standard more closely.
While the SQL standard is pretty vague on the overall topic of operatorprecedence (because it never presents a unified BNF for all expressions),it does seem reasonable to conclude from the spec for <boolean valueexpression> that OR has the lowest precedence, then AND, then NOT, then IStests, then the six standard comparison operators, then everything else(since any non-boolean operator in a WHERE clause would need to be anargument of one of these).We were only sort of on board with that: most notably, while "<" ">" and"=" had properly low precedence, "<=" ">=" and "<>" were treated as genericoperators and so had significantly higher precedence. And "IS" tests wereeven higher precedence than those, which is very clearly wrong per spec.Another problem was that "foo NOT SOMETHING bar" constructs, such as"x NOT LIKE y", were treated inconsistently because of a bisonimplementation artifact: they had the documented precedence with respectto operators to their right, but behaved like NOT (i.e., very low priority)with respect to operators to their left.Fixing the precedence issues is just a small matter of rearranging theprecedence declarations in gram.y, except for the NOT problem, whichrequires adding an additional lookahead case in base_yylex() so that wecan attach a different token precedence to NOT LIKE and allied two-wordoperators.The bulk of this patch is not the bug fix per se, but adding logic toparse_expr.c to allow giving warnings if an expression has changed meaningbecause of these precedence changes. These warnings are off by defaultand are enabled by the new GUC operator_precedence_warning. It's believedthat very few applications will be affected by these changes, but it wasagreed that a warning mechanism is essential to help debug any that are.1 parent21dcda2 commitc6b3c93
File tree
18 files changed
+723
-95
lines changed- doc/src/sgml
- src
- backend
- nodes
- parser
- utils/misc
- bin/psql
- include
- nodes
- parser
- interfaces/ecpg/preproc
- pl/plpgsql/src
18 files changed
+723
-95
lines changedLines changed: 23 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
6816 | 6816 |
| |
6817 | 6817 |
| |
6818 | 6818 |
| |
| 6819 | + | |
| 6820 | + | |
| 6821 | + | |
| 6822 | + | |
| 6823 | + | |
| 6824 | + | |
| 6825 | + | |
| 6826 | + | |
| 6827 | + | |
| 6828 | + | |
| 6829 | + | |
| 6830 | + | |
| 6831 | + | |
| 6832 | + | |
| 6833 | + | |
| 6834 | + | |
| 6835 | + | |
| 6836 | + | |
| 6837 | + | |
| 6838 | + | |
| 6839 | + | |
| 6840 | + | |
| 6841 | + | |
6819 | 6842 |
| |
6820 | 6843 |
| |
6821 | 6844 |
| |
|
Lines changed: 40 additions & 44 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
984 | 984 |
| |
985 | 985 |
| |
986 | 986 |
| |
987 |
| - | |
988 |
| - | |
989 |
| - | |
990 |
| - | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
991 | 992 |
| |
992 | 993 |
| |
993 | 994 |
| |
| |||
1008 | 1009 |
| |
1009 | 1010 |
| |
1010 | 1011 |
| |
1011 |
| - | |
| 1012 | + | |
1012 | 1013 |
| |
1013 | 1014 |
| |
1014 | 1015 |
| |
| |||
1063 | 1064 |
| |
1064 | 1065 |
| |
1065 | 1066 |
| |
1066 |
| - | |
1067 |
| - | |
1068 |
| - | |
1069 |
| - | |
1070 |
| - | |
1071 |
| - | |
1072 |
| - | |
1073 |
| - | |
1074 |
| - | |
1075 |
| - | |
1076 |
| - | |
1077 |
| - | |
1078 |
| - | |
1079 |
| - | |
1080 |
| - | |
1081 |
| - | |
1082 |
| - | |
1083 |
| - | |
1084 |
| - | |
| 1067 | + | |
1085 | 1068 |
| |
1086 | 1069 |
| |
1087 | 1070 |
| |
1088 | 1071 |
| |
1089 |
| - | |
1090 |
| - | |
1091 |
| - | |
1092 |
| - | |
1093 |
| - | |
1094 |
| - | |
1095 |
| - | |
1096 |
| - | |
1097 |
| - | |
1098 |
| - | |
1099 |
| - | |
1100 |
| - | |
1101 | 1072 |
| |
1102 | 1073 |
| |
1103 | 1074 |
| |
1104 | 1075 |
| |
1105 | 1076 |
| |
1106 | 1077 |
| |
1107 | 1078 |
| |
1108 |
| - | |
| 1079 | + | |
1109 | 1080 |
| |
1110 |
| - | |
| 1081 | + | |
1111 | 1082 |
| |
1112 | 1083 |
| |
1113 | 1084 |
| |
1114 |
| - | |
| 1085 | + | |
| 1086 | + | |
1115 | 1087 |
| |
1116 |
| - | |
| 1088 | + | |
1117 | 1089 |
| |
1118 | 1090 |
| |
1119 | 1091 |
| |
1120 |
| - | |
1121 |
| - | |
1122 |
| - | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
1123 | 1096 |
| |
1124 | 1097 |
| |
1125 | 1098 |
| |
| |||
1159 | 1132 |
| |
1160 | 1133 |
| |
1161 | 1134 |
| |
1162 |
| - | |
| 1135 | + | |
| 1136 | + | |
1163 | 1137 |
| |
1164 | 1138 |
| |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
1165 | 1161 |
| |
1166 | 1162 |
| |
1167 | 1163 |
| |
|
Lines changed: 3 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2546 | 2546 |
| |
2547 | 2547 |
| |
2548 | 2548 |
| |
| 2549 | + | |
| 2550 | + | |
| 2551 | + | |
2549 | 2552 |
| |
2550 | 2553 |
| |
2551 | 2554 |
| |
|
0 commit comments
Comments
(0)