forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit7c85032
committed
Fix SQL-style substring() to have spec-compliant greediness behavior.
SQL's regular-expression substring() function is defined to have apattern argument that's separated into three subpatterns by escape-double-quote markers; the function result is the part of the inputmatching the second subpattern. The standard makes it clear thatif there is ambiguity about how to match the input to the subpatterns,the first and third subpatterns should be taken to match the smallestpossible amount of text (i.e., they're "non greedy", in the terms ofour regex code). We were not doing it that way: the first subpatternwould eat the largest possible amount of text, causing the functionresult to be shorter than what the spec requires.Fix that by attaching explicit greediness quantifiers to thesubpatterns. (This depends on the regex fix in commit8a29ed0;before that, this didn't reliably change the regex engine's behavior.)Also, by adding parentheses around each subpattern, we ensure that"|" (OR) in the subpatterns behave sanely. Previously, "|" in thefirst or third subpatterns didn't work.This patch also makes the function throw error if you write more thantwo escape-double-quote markers, and do something sane if you writejust one, and document that behavior. Previously, an odd number ofmarkers led to a confusing complaint about unbalanced parentheses,while extra pairs of markers were just ignored. (Note that the specrequires exactly two markers, but we've historically allowed thereto be none, and this patch preserves the old behavior for that case.)In passing, adjust some substring() test cases that didn't reallyprove what they said they were testing for: they used patternsthat didn't match the data string, so that the output would beNULL whether or not the function was really strict.Although this is certainly a bug fix, changing the behavior in backbranches seems undesirable: applications could perhaps be depending onthe old behavior, since it's not obviously wrong unless you read thespec very closely. Hence, no back-patch.Discussion:https://postgr.es/m/5bb27a41-350d-37bf-901e-9d26f5592dd0@charter.net1 parentfb489e4 commit7c85032
File tree
4 files changed
+174
-26
lines changed- doc/src/sgml
- src
- backend/utils/adt
- test/regress
- expected
- sql
4 files changed
+174
-26
lines changedLines changed: 34 additions & 8 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
4296 | 4296 |
| |
4297 | 4297 |
| |
4298 | 4298 |
| |
4299 |
| - | |
4300 |
| - | |
4301 |
| - | |
4302 |
| - | |
4303 |
| - | |
4304 |
| - | |
| 4299 | + | |
| 4300 | + | |
| 4301 | + | |
| 4302 | + | |
| 4303 | + | |
| 4304 | + | |
| 4305 | + | |
| 4306 | + | |
| 4307 | + | |
| 4308 | + | |
| 4309 | + | |
| 4310 | + | |
4305 | 4311 |
| |
4306 | 4312 |
| |
4307 |
| - | |
| 4313 | + | |
| 4314 | + | |
4308 | 4315 |
| |
4309 | 4316 |
| |
4310 | 4317 |
| |
4311 |
| - | |
| 4318 | + | |
| 4319 | + | |
| 4320 | + | |
| 4321 | + | |
| 4322 | + | |
| 4323 | + | |
| 4324 | + | |
| 4325 | + | |
| 4326 | + | |
| 4327 | + | |
| 4328 | + | |
| 4329 | + | |
| 4330 | + | |
| 4331 | + | |
| 4332 | + | |
| 4333 | + | |
| 4334 | + | |
| 4335 | + | |
| 4336 | + | |
| 4337 | + | |
4312 | 4338 |
| |
4313 | 4339 |
| |
4314 | 4340 |
| |
|
Lines changed: 65 additions & 8 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
708 | 708 |
| |
709 | 709 |
| |
710 | 710 |
| |
711 |
| - | |
| 711 | + | |
712 | 712 |
| |
713 | 713 |
| |
714 | 714 |
| |
715 | 715 |
| |
716 | 716 |
| |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
717 | 738 |
| |
718 | 739 |
| |
719 | 740 |
| |
720 | 741 |
| |
721 |
| - | |
722 |
| - | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
723 | 745 |
| |
724 |
| - | |
| 746 | + | |
725 | 747 |
| |
726 | 748 |
| |
727 | 749 |
| |
| |||
760 | 782 |
| |
761 | 783 |
| |
762 | 784 |
| |
763 |
| - | |
| 785 | + | |
764 | 786 |
| |
765 | 787 |
| |
766 | 788 |
| |
| |||
784 | 806 |
| |
785 | 807 |
| |
786 | 808 |
| |
787 |
| - | |
788 |
| - | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
789 | 841 |
| |
790 | 842 |
| |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
791 | 848 |
| |
792 | 849 |
| |
793 | 850 |
| |
794 | 851 |
| |
795 | 852 |
| |
796 | 853 |
| |
797 | 854 |
| |
798 |
| - | |
| 855 | + | |
799 | 856 |
| |
800 | 857 |
| |
801 | 858 |
| |
|
Lines changed: 54 additions & 5 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
313 | 313 |
| |
314 | 314 |
| |
315 | 315 |
| |
316 |
| - | |
| 316 | + | |
317 | 317 |
| |
318 | 318 |
| |
319 | 319 |
| |
| |||
328 | 328 |
| |
329 | 329 |
| |
330 | 330 |
| |
331 |
| - | |
| 331 | + | |
332 | 332 |
| |
333 | 333 |
| |
334 | 334 |
| |
335 | 335 |
| |
336 | 336 |
| |
337 |
| - | |
| 337 | + | |
338 | 338 |
| |
339 | 339 |
| |
340 | 340 |
| |
| |||
346 | 346 |
| |
347 | 347 |
| |
348 | 348 |
| |
349 |
| - | |
350 |
| - | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
351 | 400 |
| |
352 | 401 |
| |
353 | 402 |
| |
|
Lines changed: 21 additions & 5 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
110 | 110 |
| |
111 | 111 |
| |
112 | 112 |
| |
113 |
| - | |
| 113 | + | |
114 | 114 |
| |
115 | 115 |
| |
116 | 116 |
| |
117 | 117 |
| |
118 | 118 |
| |
119 | 119 |
| |
120 |
| - | |
121 |
| - | |
| 120 | + | |
| 121 | + | |
122 | 122 |
| |
123 | 123 |
| |
124 |
| - | |
125 |
| - | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
126 | 142 |
| |
127 | 143 |
| |
128 | 144 |
| |
|
0 commit comments
Comments
(0)