forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit1e7c4bb
committed
Change unknown-type literals to type text in SELECT and RETURNING lists.
Previously, we left such literals alone if the query or subquery hadno properties forcing a type decision to be made (such as an ORDER BY orDISTINCT clause using that output column). This meant that "unknown" couldbe an exposed output column type, which has never been a great idea becauseit could result in strange failures later on. For example, an outer querythat tried to do any operations on an unknown-type subquery output wouldgenerally fail with some weird error like "failed to find conversionfunction from unknown to text" or "could not determine which collation touse for string comparison". Also, if the case occurred in a CREATE VIEW'squery then the view would have an unknown-type column, causing similarfailures in queries trying to use the view.To fix, at the tail end of parse analysis of a query, forcibly convert anyremaining "unknown" literals in its SELECT or RETURNING list to type text.However, provide a switch to suppress that, and use it in the cases ofSELECT inside a set operation or INSERT command. In those cases we alreadyhad type resolution rules that make use of context information from outsidethe subquery proper, and we don't want to change that behavior.Also, change creation of an unknown-type column in a relation from awarning to a hard error. The error should be unreachable now in CREATEVIEW or CREATE MATVIEW, but it's still possible to explicitly say "unknown"in CREATE TABLE or CREATE (composite) TYPE. We want to forbid that becauseit's nothing but a foot-gun.This change creates a pg_upgrade failure case: a matview that contains anunknown-type column can't be pg_upgraded, because reparsing the matview'sdefining query will now decide that the column is of type text, whichdoesn't match the cstring-like storage that the old materialized columnwould actually have. Add a checking pass to detect that. While at it,we can detect tables or composite types that would fail, essentiallyfor free. Those would fail safely anyway later on, but we might aswell fail earlier.This patch is by me, but it owes something to previous investigationsby Rahila Syed. Also thanks to Ashutosh Bapat and Michael Paquier forreview.Discussion:https://postgr.es/m/CAH2L28uwwbL9HUM-WR=hromW1Cvamkn7O-g8fPY2m=_7muJ0oA@mail.gmail.com1 parent123f03b commit1e7c4bb
File tree
26 files changed
+386
-36
lines changed- doc/src/sgml
- ref
- src
- backend
- catalog
- parser
- bin/pg_upgrade
- include/parser
- test/regress
- expected
- output
- sql
26 files changed
+386
-36
lines changedLines changed: 4 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
251 | 251 |
| |
252 | 252 |
| |
253 | 253 |
| |
254 |
| - | |
255 |
| - | |
256 |
| - | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
257 | 258 |
| |
258 | 259 |
| |
259 | 260 |
| |
|
Lines changed: 49 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
984 | 984 |
| |
985 | 985 |
| |
986 | 986 |
| |
987 |
| - | |
| 987 | + | |
| 988 | + | |
988 | 989 |
| |
989 | 990 |
| |
990 | 991 |
| |
| |||
1076 | 1077 |
| |
1077 | 1078 |
| |
1078 | 1079 |
| |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
| 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 | + | |
1079 | 1127 |
| |
1080 | 1128 |
| |
1081 | 1129 |
|
Lines changed: 2 additions & 12 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
490 | 490 |
| |
491 | 491 |
| |
492 | 492 |
| |
493 |
| - | |
494 |
| - | |
495 |
| - | |
496 |
| - | |
497 |
| - | |
498 |
| - | |
499 |
| - | |
500 |
| - | |
501 |
| - | |
502 |
| - | |
503 |
| - | |
504 |
| - | |
| 493 | + | |
| 494 | + | |
505 | 495 |
| |
506 | 496 |
| |
507 | 497 |
| |
|
Lines changed: 27 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
156 | 156 |
| |
157 | 157 |
| |
158 | 158 |
| |
159 |
| - | |
| 159 | + | |
| 160 | + | |
160 | 161 |
| |
161 | 162 |
| |
162 | 163 |
| |
163 | 164 |
| |
164 | 165 |
| |
165 | 166 |
| |
| 167 | + | |
166 | 168 |
| |
167 | 169 |
| |
168 | 170 |
| |
| |||
570 | 572 |
| |
571 | 573 |
| |
572 | 574 |
| |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
573 | 581 |
| |
574 | 582 |
| |
575 | 583 |
| |
576 | 584 |
| |
| 585 | + | |
577 | 586 |
| |
578 | 587 |
| |
579 | 588 |
| |
| |||
1269 | 1278 |
| |
1270 | 1279 |
| |
1271 | 1280 |
| |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
1272 | 1285 |
| |
1273 | 1286 |
| |
1274 | 1287 |
| |
| |||
1843 | 1856 |
| |
1844 | 1857 |
| |
1845 | 1858 |
| |
| 1859 | + | |
| 1860 | + | |
| 1861 | + | |
| 1862 | + | |
| 1863 | + | |
| 1864 | + | |
| 1865 | + | |
1846 | 1866 |
| |
1847 | 1867 |
| |
1848 | 1868 |
| |
1849 | 1869 |
| |
1850 |
| - | |
| 1870 | + | |
| 1871 | + | |
1851 | 1872 |
| |
1852 | 1873 |
| |
1853 | 1874 |
| |
| |||
2350 | 2371 |
| |
2351 | 2372 |
| |
2352 | 2373 |
| |
| 2374 | + | |
| 2375 | + | |
| 2376 | + | |
| 2377 | + | |
2353 | 2378 |
| |
2354 | 2379 |
| |
2355 | 2380 |
| |
|
Lines changed: 2 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
471 | 471 |
| |
472 | 472 |
| |
473 | 473 |
| |
474 |
| - | |
| 474 | + | |
| 475 | + | |
475 | 476 |
| |
476 | 477 |
| |
477 | 478 |
| |
|
Lines changed: 5 additions & 6 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
241 | 241 |
| |
242 | 242 |
| |
243 | 243 |
| |
244 |
| - | |
| 244 | + | |
245 | 245 |
| |
246 | 246 |
| |
247 | 247 |
| |
| |||
393 | 393 |
| |
394 | 394 |
| |
395 | 395 |
| |
396 |
| - | |
397 |
| - | |
398 |
| - | |
399 |
| - | |
400 |
| - | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
401 | 400 |
| |
402 | 401 |
| |
403 | 402 |
| |
|
Lines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1846 | 1846 |
| |
1847 | 1847 |
| |
1848 | 1848 |
| |
1849 |
| - | |
| 1849 | + | |
1850 | 1850 |
| |
1851 | 1851 |
| |
1852 | 1852 |
| |
|
Lines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
51 | 51 |
| |
52 | 52 |
| |
53 | 53 |
| |
| 54 | + | |
54 | 55 |
| |
55 | 56 |
| |
56 | 57 |
| |
|
Lines changed: 31 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
288 | 288 |
| |
289 | 289 |
| |
290 | 290 |
| |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
291 | 320 |
| |
292 | 321 |
| |
293 | 322 |
| |
294 | 323 |
| |
295 | 324 |
| |
296 |
| - | |
297 |
| - | |
| 325 | + | |
| 326 | + | |
298 | 327 |
| |
299 | 328 |
| |
300 | 329 |
| |
|
Lines changed: 4 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
99 | 99 |
| |
100 | 100 |
| |
101 | 101 |
| |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
102 | 106 |
| |
103 | 107 |
| |
104 | 108 |
| |
|
Lines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
442 | 442 |
| |
443 | 443 |
| |
444 | 444 |
| |
| 445 | + | |
445 | 446 |
| |
446 | 447 |
| |
447 | 448 |
| |
|
Lines changed: 97 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
185 | 185 |
| |
186 | 186 |
| |
187 | 187 |
| |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + |
0 commit comments
Comments
(0)