- Notifications
You must be signed in to change notification settings - Fork28
Commit0436f6b
committed
Disallow set-returning functions inside CASE or COALESCE.
When we reimplemented SRFs in commit69f4b9c, our initial choice wasto allow the behavior to vary from historical practice in cases where aSRF call appeared within a conditional-execution construct (currently,only CASE or COALESCE). But that was controversial to begin with, andsubsequent discussion has resulted in a consensus that it's better tothrow an error instead of executing the query differently from before,so long as we can provide a reasonably clear error message and a way torewrite the query.Hence, add a parser mechanism to allow detection of such cases duringparse analysis. The mechanism just requires storing, in the ParseState,a pointer to the set-returning FuncExpr or OpExpr most recently emittedby parse analysis. Then the parsing functions for CASE and COALESCE candetect the presence of a SRF in their arguments by noting whether thispointer changes while analyzing their arguments. Furthermore, if it does,it provides a suitable error cursor location for the complaint. (Thismeans that if there's more than one SRF in the arguments, the error willpoint at the last one to be analyzed not the first. While connoisseurs ofparsing behavior might find that odd, it's unlikely the average user wouldever notice.)While at it, we can also provide more specific error messages than beforeabout some pre-existing restrictions, such as no-SRFs-within-aggregates.Also, reject at parse time cases where a NULLIF or IS DISTINCT FROMconstruct would need to return a set. We've never supported that, but therestriction is depended on in more subtle ways now, so it seems wise todetect it at the start.Also, provide some documentation about how to rewrite a SRF-within-CASEquery using a custom wrapper SRF.It turns out that the information_schema.user_mapping_options viewcontained an instance of exactly the behavior we're now forbidding; butrewriting it makes it more clear and safer too.initdb forced because of user_mapping_options change.Patch by me, with error message suggestions from Alvaro Herrera andAndres Freund, pursuant to a complaint from Regina Obe.Discussion:https://postgr.es/m/000001d2d5de$d8d66170$8a832450$@pcorp.us1 parent39da0f7 commit0436f6b
File tree
17 files changed
+249
-91
lines changed- doc/src/sgml
- src
- backend
- catalog
- executor
- parser
- include
- catalog
- parser
- test/regress
- expected
- sql
17 files changed
+249
-91
lines changedLines changed: 58 additions & 25 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
997 | 997 |
| |
998 | 998 |
| |
999 | 999 |
| |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
1000 | 1023 |
| |
1001 | 1024 |
| |
1002 | 1025 |
| |
| |||
1028 | 1051 |
| |
1029 | 1052 |
| |
1030 | 1053 |
| |
1031 |
| - | |
1032 |
| - | |
1033 |
| - | |
1034 |
| - | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
1035 | 1057 |
| |
1036 | 1058 |
| |
1037 | 1059 |
| |
1038 |
| - | |
1039 |
| - | |
1040 |
| - | |
1041 |
| - | |
1042 |
| - | |
1043 |
| - | |
1044 |
| - | |
1045 |
| - | |
1046 |
| - | |
1047 |
| - | |
1048 |
| - | |
1049 |
| - | |
1050 |
| - | |
1051 |
| - | |
1052 |
| - | |
1053 |
| - | |
1054 |
| - | |
1055 |
| - | |
1056 |
| - | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
1057 | 1067 |
| |
1058 | 1068 |
| |
1059 | 1069 |
| |
| |||
1078 | 1088 |
| |
1079 | 1089 |
| |
1080 | 1090 |
| |
1081 |
| - | |
1082 |
| - | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
1083 | 1094 |
| |
1084 | 1095 |
| |
1085 | 1096 |
| |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
1086 | 1119 |
| |
1087 | 1120 |
| |
1088 | 1121 |
| |
|
Lines changed: 5 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2936 | 2936 |
| |
2937 | 2937 |
| |
2938 | 2938 |
| |
2939 |
| - | |
| 2939 | + | |
2940 | 2940 |
| |
2941 | 2941 |
| |
2942 |
| - | |
| 2942 | + | |
| 2943 | + | |
2943 | 2944 |
| |
2944 |
| - | |
| 2945 | + | |
| 2946 | + | |
2945 | 2947 |
| |
2946 | 2948 |
| |
2947 | 2949 |
| |
|
Lines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
388 | 388 |
| |
389 | 389 |
| |
390 | 390 |
| |
| 391 | + | |
391 | 392 |
| |
392 | 393 |
| |
393 | 394 |
| |
|
Lines changed: 8 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
705 | 705 |
| |
706 | 706 |
| |
707 | 707 |
| |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
708 | 716 |
| |
709 | 717 |
| |
710 | 718 |
| |
|
Lines changed: 32 additions & 6 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
572 | 572 |
| |
573 | 573 |
| |
574 | 574 |
| |
| 575 | + | |
| 576 | + | |
575 | 577 |
| |
576 | 578 |
| |
577 | 579 |
| |
| |||
618 | 620 |
| |
619 | 621 |
| |
620 | 622 |
| |
| 623 | + | |
| 624 | + | |
621 | 625 |
| |
622 | 626 |
| |
623 | 627 |
| |
624 | 628 |
| |
625 |
| - | |
626 |
| - | |
627 |
| - | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
628 | 642 |
| |
629 | 643 |
| |
630 | 644 |
| |
| |||
638 | 652 |
| |
639 | 653 |
| |
640 | 654 |
| |
641 |
| - | |
642 |
| - | |
643 |
| - | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
644 | 670 |
| |
645 | 671 |
| |
646 | 672 |
| |
|
0 commit comments
Comments
(0)