forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitece2969
committed
Fix scale clamping in numeric round() and trunc().
The numeric round() and trunc() functions clamp the scale argument tothe range between +/- NUMERIC_MAX_RESULT_SCALE (2000), which is muchsmaller than the actual allowed range of type numeric. As a result,they return incorrect results when asked to round/truncate more than2000 digits before or after the decimal point.Fix by using the correct upper and lower scale limits based on theactual allowed (and documented) range of type numeric.While at it, use the new NUMERIC_WEIGHT_MAX constant instead ofSHRT_MAX in all other overflow checks, and fix a comment thinko inpower_var() introduced bye54a758 -- the minimum value ofln_dweight is -NUMERIC_DSCALE_MAX (-16383), not -SHRT_MAX, though thisdoesn't affect the point being made in the comment, that the resultinglocal_rscale value may exceed NUMERIC_MAX_DISPLAY_SCALE (1000).Back-patch to all supported branches.Dean Rasheed, reviewed by Joel Jacobson.Discussion:https://postgr.es/m/CAEZATCXB%2BrDTuMjhK5ZxcouufigSc-X4tGJCBTMpZ3n%3DxxQuhg%40mail.gmail.com1 parent440aedc commitece2969
File tree
3 files changed
+153
-9
lines changed- src
- backend/utils/adt
- test/regress
- expected
- sql
3 files changed
+153
-9
lines changedLines changed: 26 additions & 9 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
221 | 221 |
| |
222 | 222 |
| |
223 | 223 |
| |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
224 | 231 |
| |
225 | 232 |
| |
226 | 233 |
| |
| |||
1230 | 1237 |
| |
1231 | 1238 |
| |
1232 | 1239 |
| |
1233 |
| - | |
| 1240 | + | |
| 1241 | + | |
| 1242 | + | |
| 1243 | + | |
| 1244 | + | |
| 1245 | + | |
1234 | 1246 |
| |
1235 |
| - | |
1236 |
| - | |
| 1247 | + | |
| 1248 | + | |
1237 | 1249 |
| |
1238 | 1250 |
| |
1239 | 1251 |
| |
| |||
1279 | 1291 |
| |
1280 | 1292 |
| |
1281 | 1293 |
| |
1282 |
| - | |
| 1294 | + | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
1283 | 1298 |
| |
1284 |
| - | |
1285 |
| - | |
| 1299 | + | |
| 1300 | + | |
1286 | 1301 |
| |
1287 | 1302 |
| |
1288 | 1303 |
| |
| |||
9256 | 9271 |
| |
9257 | 9272 |
| |
9258 | 9273 |
| |
9259 |
| - | |
| 9274 | + | |
| 9275 | + | |
9260 | 9276 |
| |
9261 | 9277 |
| |
9262 | 9278 |
| |
| |||
9396 | 9412 |
| |
9397 | 9413 |
| |
9398 | 9414 |
| |
9399 |
| - | |
| 9415 | + | |
9400 | 9416 |
| |
9401 | 9417 |
| |
9402 | 9418 |
| |
| |||
9466 | 9482 |
| |
9467 | 9483 |
| |
9468 | 9484 |
| |
9469 |
| - | |
| 9485 | + | |
| 9486 | + | |
9470 | 9487 |
| |
9471 | 9488 |
| |
9472 | 9489 |
| |
|
Lines changed: 102 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
824 | 824 |
| |
825 | 825 |
| |
826 | 826 |
| |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
827 | 929 |
| |
828 | 930 |
| |
829 | 931 |
| |
|
Lines changed: 25 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
699 | 699 |
| |
700 | 700 |
| |
701 | 701 |
| |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
702 | 727 |
| |
703 | 728 |
| |
704 | 729 |
| |
|
0 commit comments
Comments
(0)