forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commite02d44b
committed
Support JSON negative array subscripts everywhere
Previously, there was an inconsistency across json/jsonb operators thatoperate on datums containing JSON arrays -- only some operatorssupported negative array count-from-the-end subscripting. Specifically,only a new-to-9.5 jsonb deletion operator had support (the new "jsonb -integer" operator). This inconsistency seemed likely to becounter-intuitive to users. To fix, allow all places where the user cansupply an integer subscript to accept a negative subscript value,including path-orientated operators and functions, as well as otherextraction operators. This will need to be called out as anincompatibility in the 9.5 release notes, since it's possible that usersare relying on certain established extraction operators changed hereyielding NULL in the event of a negative subscript.For the json type, this requires adding a way of cheaply getting thetotal JSON array element count ahead of time when parsing arrays with anegative subscript involved, necessitating an ad-hoc lex and parse.This is followed by a "conversion" from a negative subscript to itsequivalent positive-wise value using the count. From there on, it's asif a positive-wise value was originally provided.Note that there is still a minor inconsistency here across jsonbdeletion operators. Unlike the aforementioned new "-" deletion operatorthat accepts an integer on its right hand side, the new "#-" pathorientated deletion variant does not throw an error when it appears likean array subscript (input that could be recognized by as an integerliteral) is being used on an object, which is wrong-headed. The reasonfor not being stricter is that it could be the case that an object pairhappens to have a key value that looks like an integer; in general,these two possibilities are impossible to differentiate with rhs pathtext[] argument elements. However, we still don't allow the "#-"path-orientated deletion operator to perform array-style subscripting.Rather, we just return the original left operand value in the event of anegative subscript (which seems analogous to how the established"jsonb/json #> text[]" path-orientated operator may yield NULL in theevent of an invalid subscript).In passing, make SetArrayPath() stricter about not accepting cases wherethere is trailing non-numeric garbage bytes rather than a clean NULbyte. This means, for example, that strings like "10e10" are now notaccepted as an array subscript of 10 by some new-to-9.5 path-orientatedjsonb operators (e.g. the new #- operator). Finally, remove dead codefor jsonb subscript deletion; arguably, this should have been done incommitb81c7b4.Peter Geoghegan and Andrew Dunstan1 parent0fc94a5 commite02d44b
File tree
10 files changed
+231
-29
lines changed- doc/src/sgml
- src
- backend/utils/adt
- include/utils
- test/regress
- expected
- sql
10 files changed
+231
-29
lines changedLines changed: 12 additions & 4 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
10177 | 10177 |
| |
10178 | 10178 |
| |
10179 | 10179 |
| |
10180 |
| - | |
| 10180 | + | |
| 10181 | + | |
10181 | 10182 |
| |
10182 | 10183 |
| |
10183 | 10184 |
| |
| |||
10230 | 10231 |
| |
10231 | 10232 |
| |
10232 | 10233 |
| |
10233 |
| - | |
| 10234 | + | |
| 10235 | + | |
| 10236 | + | |
| 10237 | + | |
10234 | 10238 |
| |
10235 | 10239 |
| |
10236 | 10240 |
| |
| |||
10318 | 10322 |
| |
10319 | 10323 |
| |
10320 | 10324 |
| |
10321 |
| - | |
| 10325 | + | |
| 10326 | + | |
10322 | 10327 |
| |
10323 | 10328 |
| |
10324 | 10329 |
| |
| |||
10858 | 10863 |
| |
10859 | 10864 |
| |
10860 | 10865 |
| |
| 10866 | + | |
| 10867 | + | |
| 10868 | + | |
10861 | 10869 |
| |
10862 | 10870 |
| |
10863 | 10871 |
| |
| |||
10872 | 10880 |
| |
10873 | 10881 |
| |
10874 | 10882 |
| |
10875 |
| - | |
| 10883 | + | |
10876 | 10884 |
| |
10877 | 10885 |
| |
10878 | 10886 |
| |
|
Lines changed: 39 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
340 | 340 |
| |
341 | 341 |
| |
342 | 342 |
| |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 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 | + | |
343 | 382 |
| |
344 | 383 |
| |
345 | 384 |
| |
|
Lines changed: 75 additions & 25 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
597 | 597 |
| |
598 | 598 |
| |
599 | 599 |
| |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
600 | 611 |
| |
601 | 612 |
| |
602 | 613 |
| |
| |||
629 | 640 |
| |
630 | 641 |
| |
631 | 642 |
| |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
632 | 654 |
| |
633 | 655 |
| |
634 | 656 |
| |
| |||
719 | 741 |
| |
720 | 742 |
| |
721 | 743 |
| |
722 |
| - | |
| 744 | + | |
723 | 745 |
| |
724 | 746 |
| |
725 | 747 |
| |
| |||
728 | 750 |
| |
729 | 751 |
| |
730 | 752 |
| |
731 |
| - | |
| 753 | + | |
732 | 754 |
| |
733 | 755 |
| |
734 |
| - | |
| 756 | + | |
735 | 757 |
| |
736 | 758 |
| |
737 |
| - | |
| 759 | + | |
738 | 760 |
| |
739 | 761 |
| |
740 | 762 |
| |
| |||
752 | 774 |
| |
753 | 775 |
| |
754 | 776 |
| |
755 |
| - | |
| 777 | + | |
756 | 778 |
| |
757 | 779 |
| |
758 | 780 |
| |
759 | 781 |
| |
760 | 782 |
| |
761 |
| - | |
762 |
| - | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
763 | 786 |
| |
764 | 787 |
| |
765 | 788 |
| |
| |||
964 | 987 |
| |
965 | 988 |
| |
966 | 989 |
| |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
967 | 1001 |
| |
968 | 1002 |
| |
969 | 1003 |
| |
| |||
1209 | 1243 |
| |
1210 | 1244 |
| |
1211 | 1245 |
| |
1212 |
| - | |
| 1246 | + | |
1213 | 1247 |
| |
1214 |
| - | |
| 1248 | + | |
| 1249 | + | |
| 1250 | + | |
| 1251 | + | |
| 1252 | + | |
| 1253 | + | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
| 1257 | + | |
| 1258 | + | |
| 1259 | + | |
| 1260 | + | |
| 1261 | + | |
| 1262 | + | |
| 1263 | + | |
| 1264 | + | |
| 1265 | + | |
| 1266 | + | |
| 1267 | + | |
| 1268 | + | |
| 1269 | + | |
1215 | 1270 |
| |
1216 | 1271 |
| |
1217 | 1272 |
| |
| |||
3411 | 3466 |
| |
3412 | 3467 |
| |
3413 | 3468 |
| |
3414 |
| - | |
3415 |
| - | |
3416 |
| - | |
3417 |
| - | |
| 3469 | + | |
| 3470 | + | |
3418 | 3471 |
| |
3419 | 3472 |
| |
3420 | 3473 |
| |
| |||
3431 | 3484 |
| |
3432 | 3485 |
| |
3433 | 3486 |
| |
3434 |
| - | |
| 3487 | + | |
3435 | 3488 |
| |
3436 | 3489 |
| |
3437 |
| - | |
3438 |
| - | |
3439 |
| - | |
3440 | 3490 |
| |
3441 |
| - | |
3442 | 3491 |
| |
3443 | 3492 |
| |
3444 | 3493 |
| |
| |||
3657 | 3706 |
| |
3658 | 3707 |
| |
3659 | 3708 |
| |
3660 |
| - | |
| 3709 | + | |
3661 | 3710 |
| |
3662 | 3711 |
| |
3663 | 3712 |
| |
| |||
3818 | 3867 |
| |
3819 | 3868 |
| |
3820 | 3869 |
| |
3821 |
| - | |
| 3870 | + | |
| 3871 | + | |
3822 | 3872 |
| |
3823 | 3873 |
| |
3824 | 3874 |
| |
| |||
3829 | 3879 |
| |
3830 | 3880 |
| |
3831 | 3881 |
| |
3832 |
| - | |
| 3882 | + | |
3833 | 3883 |
| |
3834 | 3884 |
| |
3835 | 3885 |
| |
| |||
3838 | 3888 |
| |
3839 | 3889 |
| |
3840 | 3890 |
| |
3841 |
| - | |
3842 |
| - | |
3843 |
| - | |
| 3891 | + | |
| 3892 | + | |
| 3893 | + | |
3844 | 3894 |
| |
3845 | 3895 |
| |
3846 |
| - | |
| 3896 | + | |
3847 | 3897 |
| |
3848 | 3898 |
| |
3849 | 3899 |
| |
|
Lines changed: 7 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
103 | 103 |
| |
104 | 104 |
| |
105 | 105 |
| |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
106 | 113 |
| |
107 | 114 |
| |
108 | 115 |
| |
|
Lines changed: 14 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
569 | 569 |
| |
570 | 570 |
| |
571 | 571 |
| |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
572 | 580 |
| |
573 | 581 |
| |
574 | 582 |
| |
| |||
698 | 706 |
| |
699 | 707 |
| |
700 | 708 |
| |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
701 | 715 |
| |
702 | 716 |
| |
703 | 717 |
| |
|
Lines changed: 14 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
569 | 569 |
| |
570 | 570 |
| |
571 | 571 |
| |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
572 | 580 |
| |
573 | 581 |
| |
574 | 582 |
| |
| |||
698 | 706 |
| |
699 | 707 |
| |
700 | 708 |
| |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
701 | 715 |
| |
702 | 716 |
| |
703 | 717 |
| |
|
0 commit comments
Comments
(0)