4 CREATE TABLE num_data (id int4, val numeric(210,10));
5 CREATE TABLE num_exp_add (id1 int4, id2 int4, expected numeric(210,10));
6 CREATE TABLE num_exp_sub (id1 int4, id2 int4, expected numeric(210,10));
7 CREATE TABLE num_exp_div (id1 int4, id2 int4, expected numeric(210,10));
8 CREATE TABLE num_exp_mul (id1 int4, id2 int4, expected numeric(210,10));
9 CREATE TABLE num_exp_sqrt (id int4, expected numeric(210,10));
10 CREATE TABLE num_exp_ln (id int4, expected numeric(210,10));
11 CREATE TABLE num_exp_log10 (id int4, expected numeric(210,10));
12 CREATE TABLE num_exp_power_10_ln (id int4, expected numeric(210,10));
13 CREATE TABLE num_result (id1 int4, id2 int4, result numeric(210,10));
14 -- ******************************
15 -- * The following EXPECTED results are computed by bc(1)
16 -- * with a scale of 200
17 -- ******************************
19 INSERT INTO num_exp_add VALUES (0,0,'0');
20 INSERT INTO num_exp_sub VALUES (0,0,'0');
21 INSERT INTO num_exp_mul VALUES (0,0,'0');
22 INSERT INTO num_exp_div VALUES (0,0,'NaN');
23 INSERT INTO num_exp_add VALUES (0,1,'0');
24 INSERT INTO num_exp_sub VALUES (0,1,'0');
25 INSERT INTO num_exp_mul VALUES (0,1,'0');
26 INSERT INTO num_exp_div VALUES (0,1,'NaN');
27 INSERT INTO num_exp_add VALUES (0,2,'-34338492.215397047');
28 INSERT INTO num_exp_sub VALUES (0,2,'34338492.215397047');
29 INSERT INTO num_exp_mul VALUES (0,2,'0');
30 INSERT INTO num_exp_div VALUES (0,2,'0');
31 INSERT INTO num_exp_add VALUES (0,3,'4.31');
32 INSERT INTO num_exp_sub VALUES (0,3,'-4.31');
33 INSERT INTO num_exp_mul VALUES (0,3,'0');
34 INSERT INTO num_exp_div VALUES (0,3,'0');
35 INSERT INTO num_exp_add VALUES (0,4,'7799461.4119');
36 INSERT INTO num_exp_sub VALUES (0,4,'-7799461.4119');
37 INSERT INTO num_exp_mul VALUES (0,4,'0');
38 INSERT INTO num_exp_div VALUES (0,4,'0');
39 INSERT INTO num_exp_add VALUES (0,5,'16397.038491');
40 INSERT INTO num_exp_sub VALUES (0,5,'-16397.038491');
41 INSERT INTO num_exp_mul VALUES (0,5,'0');
42 INSERT INTO num_exp_div VALUES (0,5,'0');
43 INSERT INTO num_exp_add VALUES (0,6,'93901.57763026');
44 INSERT INTO num_exp_sub VALUES (0,6,'-93901.57763026');
45 INSERT INTO num_exp_mul VALUES (0,6,'0');
46 INSERT INTO num_exp_div VALUES (0,6,'0');
47 INSERT INTO num_exp_add VALUES (0,7,'-83028485');
48 INSERT INTO num_exp_sub VALUES (0,7,'83028485');
49 INSERT INTO num_exp_mul VALUES (0,7,'0');
50 INSERT INTO num_exp_div VALUES (0,7,'0');
51 INSERT INTO num_exp_add VALUES (0,8,'74881');
52 INSERT INTO num_exp_sub VALUES (0,8,'-74881');
53 INSERT INTO num_exp_mul VALUES (0,8,'0');
54 INSERT INTO num_exp_div VALUES (0,8,'0');
55 INSERT INTO num_exp_add VALUES (0,9,'-24926804.045047420');
56 INSERT INTO num_exp_sub VALUES (0,9,'24926804.045047420');
57 INSERT INTO num_exp_mul VALUES (0,9,'0');
58 INSERT INTO num_exp_div VALUES (0,9,'0');
59 INSERT INTO num_exp_add VALUES (1,0,'0');
60 INSERT INTO num_exp_sub VALUES (1,0,'0');
61 INSERT INTO num_exp_mul VALUES (1,0,'0');
62 INSERT INTO num_exp_div VALUES (1,0,'NaN');
63 INSERT INTO num_exp_add VALUES (1,1,'0');
64 INSERT INTO num_exp_sub VALUES (1,1,'0');
65 INSERT INTO num_exp_mul VALUES (1,1,'0');
66 INSERT INTO num_exp_div VALUES (1,1,'NaN');
67 INSERT INTO num_exp_add VALUES (1,2,'-34338492.215397047');
68 INSERT INTO num_exp_sub VALUES (1,2,'34338492.215397047');
69 INSERT INTO num_exp_mul VALUES (1,2,'0');
70 INSERT INTO num_exp_div VALUES (1,2,'0');
71 INSERT INTO num_exp_add VALUES (1,3,'4.31');
72 INSERT INTO num_exp_sub VALUES (1,3,'-4.31');
73 INSERT INTO num_exp_mul VALUES (1,3,'0');
74 INSERT INTO num_exp_div VALUES (1,3,'0');
75 INSERT INTO num_exp_add VALUES (1,4,'7799461.4119');
76 INSERT INTO num_exp_sub VALUES (1,4,'-7799461.4119');
77 INSERT INTO num_exp_mul VALUES (1,4,'0');
78 INSERT INTO num_exp_div VALUES (1,4,'0');
79 INSERT INTO num_exp_add VALUES (1,5,'16397.038491');
80 INSERT INTO num_exp_sub VALUES (1,5,'-16397.038491');
81 INSERT INTO num_exp_mul VALUES (1,5,'0');
82 INSERT INTO num_exp_div VALUES (1,5,'0');
83 INSERT INTO num_exp_add VALUES (1,6,'93901.57763026');
84 INSERT INTO num_exp_sub VALUES (1,6,'-93901.57763026');
85 INSERT INTO num_exp_mul VALUES (1,6,'0');
86 INSERT INTO num_exp_div VALUES (1,6,'0');
87 INSERT INTO num_exp_add VALUES (1,7,'-83028485');
88 INSERT INTO num_exp_sub VALUES (1,7,'83028485');
89 INSERT INTO num_exp_mul VALUES (1,7,'0');
90 INSERT INTO num_exp_div VALUES (1,7,'0');
91 INSERT INTO num_exp_add VALUES (1,8,'74881');
92 INSERT INTO num_exp_sub VALUES (1,8,'-74881');
93 INSERT INTO num_exp_mul VALUES (1,8,'0');
94 INSERT INTO num_exp_div VALUES (1,8,'0');
95 INSERT INTO num_exp_add VALUES (1,9,'-24926804.045047420');
96 INSERT INTO num_exp_sub VALUES (1,9,'24926804.045047420');
97 INSERT INTO num_exp_mul VALUES (1,9,'0');
98 INSERT INTO num_exp_div VALUES (1,9,'0');
99 INSERT INTO num_exp_add VALUES (2,0,'-34338492.215397047');
100 INSERT INTO num_exp_sub VALUES (2,0,'-34338492.215397047');
101 INSERT INTO num_exp_mul VALUES (2,0,'0');
102 INSERT INTO num_exp_div VALUES (2,0,'NaN');
103 INSERT INTO num_exp_add VALUES (2,1,'-34338492.215397047');
104 INSERT INTO num_exp_sub VALUES (2,1,'-34338492.215397047');
105 INSERT INTO num_exp_mul VALUES (2,1,'0');
106 INSERT INTO num_exp_div VALUES (2,1,'NaN');
107 INSERT INTO num_exp_add VALUES (2,2,'-68676984.430794094');
108 INSERT INTO num_exp_sub VALUES (2,2,'0');
109 INSERT INTO num_exp_mul VALUES (2,2,'1179132047626883.596862135856320209');
110 INSERT INTO num_exp_div VALUES (2,2,'1.00000000000000000000');
111 INSERT INTO num_exp_add VALUES (2,3,'-34338487.905397047');
112 INSERT INTO num_exp_sub VALUES (2,3,'-34338496.525397047');
113 INSERT INTO num_exp_mul VALUES (2,3,'-147998901.44836127257');
114 INSERT INTO num_exp_div VALUES (2,3,'-7967167.56737750510440835266');
115 INSERT INTO num_exp_add VALUES (2,4,'-26539030.803497047');
116 INSERT INTO num_exp_sub VALUES (2,4,'-42137953.627297047');
117 INSERT INTO num_exp_mul VALUES (2,4,'-267821744976817.8111137106593');
118 INSERT INTO num_exp_div VALUES (2,4,'-4.40267480046830116685');
119 INSERT INTO num_exp_add VALUES (2,5,'-34322095.176906047');
120 INSERT INTO num_exp_sub VALUES (2,5,'-34354889.253888047');
121 INSERT INTO num_exp_mul VALUES (2,5,'-563049578578.769242506736077');
122 INSERT INTO num_exp_div VALUES (2,5,'-2094.18866914563535496429');
123 INSERT INTO num_exp_add VALUES (2,6,'-34244590.637766787');
124 INSERT INTO num_exp_sub VALUES (2,6,'-34432393.793027307');
125 INSERT INTO num_exp_mul VALUES (2,6,'-3224438592470.18449811926184222');
126 INSERT INTO num_exp_div VALUES (2,6,'-365.68599891479766440940');
127 INSERT INTO num_exp_add VALUES (2,7,'-117366977.215397047');
128 INSERT INTO num_exp_sub VALUES (2,7,'48689992.784602953');
129 INSERT INTO num_exp_mul VALUES (2,7,'2851072985828710.485883795');
130 INSERT INTO num_exp_div VALUES (2,7,'.41357483778485235518');
131 INSERT INTO num_exp_add VALUES (2,8,'-34263611.215397047');
132 INSERT INTO num_exp_sub VALUES (2,8,'-34413373.215397047');
133 INSERT INTO num_exp_mul VALUES (2,8,'-2571300635581.146276407');
134 INSERT INTO num_exp_div VALUES (2,8,'-458.57416721727870888476');
135 INSERT INTO num_exp_add VALUES (2,9,'-59265296.260444467');
136 INSERT INTO num_exp_sub VALUES (2,9,'-9411688.170349627');
137 INSERT INTO num_exp_mul VALUES (2,9,'855948866655588.453741509242968740');
138 INSERT INTO num_exp_div VALUES (2,9,'1.37757299946438931811');
139 INSERT INTO num_exp_add VALUES (3,0,'4.31');
140 INSERT INTO num_exp_sub VALUES (3,0,'4.31');
141 INSERT INTO num_exp_mul VALUES (3,0,'0');
142 INSERT INTO num_exp_div VALUES (3,0,'NaN');
143 INSERT INTO num_exp_add VALUES (3,1,'4.31');
144 INSERT INTO num_exp_sub VALUES (3,1,'4.31');
145 INSERT INTO num_exp_mul VALUES (3,1,'0');
146 INSERT INTO num_exp_div VALUES (3,1,'NaN');
147 INSERT INTO num_exp_add VALUES (3,2,'-34338487.905397047');
148 INSERT INTO num_exp_sub VALUES (3,2,'34338496.525397047');
149 INSERT INTO num_exp_mul VALUES (3,2,'-147998901.44836127257');
150 INSERT INTO num_exp_div VALUES (3,2,'-.00000012551512084352');
151 INSERT INTO num_exp_add VALUES (3,3,'8.62');
152 INSERT INTO num_exp_sub VALUES (3,3,'0');
153 INSERT INTO num_exp_mul VALUES (3,3,'18.5761');
154 INSERT INTO num_exp_div VALUES (3,3,'1.00000000000000000000');
155 INSERT INTO num_exp_add VALUES (3,4,'7799465.7219');
156 INSERT INTO num_exp_sub VALUES (3,4,'-7799457.1019');
157 INSERT INTO num_exp_mul VALUES (3,4,'33615678.685289');
158 INSERT INTO num_exp_div VALUES (3,4,'.00000055260225961552');
159 INSERT INTO num_exp_add VALUES (3,5,'16401.348491');
160 INSERT INTO num_exp_sub VALUES (3,5,'-16392.728491');
161 INSERT INTO num_exp_mul VALUES (3,5,'70671.23589621');
162 INSERT INTO num_exp_div VALUES (3,5,'.00026285234387695504');
163 INSERT INTO num_exp_add VALUES (3,6,'93905.88763026');
164 INSERT INTO num_exp_sub VALUES (3,6,'-93897.26763026');
165 INSERT INTO num_exp_mul VALUES (3,6,'404715.7995864206');
166 INSERT INTO num_exp_div VALUES (3,6,'.00004589912234457595');
167 INSERT INTO num_exp_add VALUES (3,7,'-83028480.69');
168 INSERT INTO num_exp_sub VALUES (3,7,'83028489.31');
169 INSERT INTO num_exp_mul VALUES (3,7,'-357852770.35');
170 INSERT INTO num_exp_div VALUES (3,7,'-.00000005190989574240');
171 INSERT INTO num_exp_add VALUES (3,8,'74885.31');
172 INSERT INTO num_exp_sub VALUES (3,8,'-74876.69');
173 INSERT INTO num_exp_mul VALUES (3,8,'322737.11');
174 INSERT INTO num_exp_div VALUES (3,8,'.00005755799201399553');
175 INSERT INTO num_exp_add VALUES (3,9,'-24926799.735047420');
176 INSERT INTO num_exp_sub VALUES (3,9,'24926808.355047420');
177 INSERT INTO num_exp_mul VALUES (3,9,'-107434525.43415438020');
178 INSERT INTO num_exp_div VALUES (3,9,'-.00000017290624149854');
179 INSERT INTO num_exp_add VALUES (4,0,'7799461.4119');
180 INSERT INTO num_exp_sub VALUES (4,0,'7799461.4119');
181 INSERT INTO num_exp_mul VALUES (4,0,'0');
182 INSERT INTO num_exp_div VALUES (4,0,'NaN');
183 INSERT INTO num_exp_add VALUES (4,1,'7799461.4119');
184 INSERT INTO num_exp_sub VALUES (4,1,'7799461.4119');
185 INSERT INTO num_exp_mul VALUES (4,1,'0');
186 INSERT INTO num_exp_div VALUES (4,1,'NaN');
187 INSERT INTO num_exp_add VALUES (4,2,'-26539030.803497047');
188 INSERT INTO num_exp_sub VALUES (4,2,'42137953.627297047');
189 INSERT INTO num_exp_mul VALUES (4,2,'-267821744976817.8111137106593');
190 INSERT INTO num_exp_div VALUES (4,2,'-.22713465002993920385');
191 INSERT INTO num_exp_add VALUES (4,3,'7799465.7219');
192 INSERT INTO num_exp_sub VALUES (4,3,'7799457.1019');
193 INSERT INTO num_exp_mul VALUES (4,3,'33615678.685289');
194 INSERT INTO num_exp_div VALUES (4,3,'1809619.81714617169373549883');
195 INSERT INTO num_exp_add VALUES (4,4,'15598922.8238');
196 INSERT INTO num_exp_sub VALUES (4,4,'0');
197 INSERT INTO num_exp_mul VALUES (4,4,'60831598315717.14146161');
198 INSERT INTO num_exp_div VALUES (4,4,'1.00000000000000000000');
199 INSERT INTO num_exp_add VALUES (4,5,'7815858.450391');
200 INSERT INTO num_exp_sub VALUES (4,5,'7783064.373409');
201 INSERT INTO num_exp_mul VALUES (4,5,'127888068979.9935054429');
202 INSERT INTO num_exp_div VALUES (4,5,'475.66281046305802686061');
203 INSERT INTO num_exp_add VALUES (4,6,'7893362.98953026');
204 INSERT INTO num_exp_sub VALUES (4,6,'7705559.83426974');
205 INSERT INTO num_exp_mul VALUES (4,6,'732381731243.745115764094');
206 INSERT INTO num_exp_div VALUES (4,6,'83.05996138436129499606');
207 INSERT INTO num_exp_add VALUES (4,7,'-75229023.5881');
208 INSERT INTO num_exp_sub VALUES (4,7,'90827946.4119');
209 INSERT INTO num_exp_mul VALUES (4,7,'-647577464846017.9715');
210 INSERT INTO num_exp_div VALUES (4,7,'-.09393717604145131637');
211 INSERT INTO num_exp_add VALUES (4,8,'7874342.4119');
212 INSERT INTO num_exp_sub VALUES (4,8,'7724580.4119');
213 INSERT INTO num_exp_mul VALUES (4,8,'584031469984.4839');
214 INSERT INTO num_exp_div VALUES (4,8,'104.15808298366741897143');
215 INSERT INTO num_exp_add VALUES (4,9,'-17127342.633147420');
216 INSERT INTO num_exp_sub VALUES (4,9,'32726265.456947420');
217 INSERT INTO num_exp_mul VALUES (4,9,'-194415646271340.1815956522980');
218 INSERT INTO num_exp_div VALUES (4,9,'-.31289456112403769409');
219 INSERT INTO num_exp_add VALUES (5,0,'16397.038491');
220 INSERT INTO num_exp_sub VALUES (5,0,'16397.038491');
221 INSERT INTO num_exp_mul VALUES (5,0,'0');
222 INSERT INTO num_exp_div VALUES (5,0,'NaN');
223 INSERT INTO num_exp_add VALUES (5,1,'16397.038491');
224 INSERT INTO num_exp_sub VALUES (5,1,'16397.038491');
225 INSERT INTO num_exp_mul VALUES (5,1,'0');
226 INSERT INTO num_exp_div VALUES (5,1,'NaN');
227 INSERT INTO num_exp_add VALUES (5,2,'-34322095.176906047');
228 INSERT INTO num_exp_sub VALUES (5,2,'34354889.253888047');
229 INSERT INTO num_exp_mul VALUES (5,2,'-563049578578.769242506736077');
230 INSERT INTO num_exp_div VALUES (5,2,'-.00047751189505192446');
231 INSERT INTO num_exp_add VALUES (5,3,'16401.348491');
232 INSERT INTO num_exp_sub VALUES (5,3,'16392.728491');
233 INSERT INTO num_exp_mul VALUES (5,3,'70671.23589621');
234 INSERT INTO num_exp_div VALUES (5,3,'3804.41728329466357308584');
235 INSERT INTO num_exp_add VALUES (5,4,'7815858.450391');
236 INSERT INTO num_exp_sub VALUES (5,4,'-7783064.373409');
237 INSERT INTO num_exp_mul VALUES (5,4,'127888068979.9935054429');
238 INSERT INTO num_exp_div VALUES (5,4,'.00210232958726897192');
239 INSERT INTO num_exp_add VALUES (5,5,'32794.076982');
240 INSERT INTO num_exp_sub VALUES (5,5,'0');
241 INSERT INTO num_exp_mul VALUES (5,5,'268862871.275335557081');
242 INSERT INTO num_exp_div VALUES (5,5,'1.00000000000000000000');
243 INSERT INTO num_exp_add VALUES (5,6,'110298.61612126');
244 INSERT INTO num_exp_sub VALUES (5,6,'-77504.53913926');
245 INSERT INTO num_exp_mul VALUES (5,6,'1539707782.76899778633766');
246 INSERT INTO num_exp_div VALUES (5,6,'.17461941433576102689');
247 INSERT INTO num_exp_add VALUES (5,7,'-83012087.961509');
248 INSERT INTO num_exp_sub VALUES (5,7,'83044882.038491');
249 INSERT INTO num_exp_mul VALUES (5,7,'-1361421264394.416135');
250 INSERT INTO num_exp_div VALUES (5,7,'-.00019748690453643710');
251 INSERT INTO num_exp_add VALUES (5,8,'91278.038491');
252 INSERT INTO num_exp_sub VALUES (5,8,'-58483.961509');
253 INSERT INTO num_exp_mul VALUES (5,8,'1227826639.244571');
254 INSERT INTO num_exp_div VALUES (5,8,'.21897461960978085228');
255 INSERT INTO num_exp_add VALUES (5,9,'-24910407.006556420');
256 INSERT INTO num_exp_sub VALUES (5,9,'24943201.083538420');
257 INSERT INTO num_exp_mul VALUES (5,9,'-408725765384.257043660243220');
258 INSERT INTO num_exp_div VALUES (5,9,'-.00065780749354660427');
259 INSERT INTO num_exp_add VALUES (6,0,'93901.57763026');
260 INSERT INTO num_exp_sub VALUES (6,0,'93901.57763026');
261 INSERT INTO num_exp_mul VALUES (6,0,'0');
262 INSERT INTO num_exp_div VALUES (6,0,'NaN');
263 INSERT INTO num_exp_add VALUES (6,1,'93901.57763026');
264 INSERT INTO num_exp_sub VALUES (6,1,'93901.57763026');
265 INSERT INTO num_exp_mul VALUES (6,1,'0');
266 INSERT INTO num_exp_div VALUES (6,1,'NaN');
267 INSERT INTO num_exp_add VALUES (6,2,'-34244590.637766787');
268 INSERT INTO num_exp_sub VALUES (6,2,'34432393.793027307');
269 INSERT INTO num_exp_mul VALUES (6,2,'-3224438592470.18449811926184222');
270 INSERT INTO num_exp_div VALUES (6,2,'-.00273458651128995823');
271 INSERT INTO num_exp_add VALUES (6,3,'93905.88763026');
272 INSERT INTO num_exp_sub VALUES (6,3,'93897.26763026');
273 INSERT INTO num_exp_mul VALUES (6,3,'404715.7995864206');
274 INSERT INTO num_exp_div VALUES (6,3,'21786.90896293735498839907');
275 INSERT INTO num_exp_add VALUES (6,4,'7893362.98953026');
276 INSERT INTO num_exp_sub VALUES (6,4,'-7705559.83426974');
277 INSERT INTO num_exp_mul VALUES (6,4,'732381731243.745115764094');
278 INSERT INTO num_exp_div VALUES (6,4,'.01203949512295682469');
279 INSERT INTO num_exp_add VALUES (6,5,'110298.61612126');
280 INSERT INTO num_exp_sub VALUES (6,5,'77504.53913926');
281 INSERT INTO num_exp_mul VALUES (6,5,'1539707782.76899778633766');
282 INSERT INTO num_exp_div VALUES (6,5,'5.72674008674192359679');
283 INSERT INTO num_exp_add VALUES (6,6,'187803.15526052');
284 INSERT INTO num_exp_sub VALUES (6,6,'0');
285 INSERT INTO num_exp_mul VALUES (6,6,'8817506281.4517452372676676');
286 INSERT INTO num_exp_div VALUES (6,6,'1.00000000000000000000');
287 INSERT INTO num_exp_add VALUES (6,7,'-82934583.42236974');
288 INSERT INTO num_exp_sub VALUES (6,7,'83122386.57763026');
289 INSERT INTO num_exp_mul VALUES (6,7,'-7796505729750.37795610');
290 INSERT INTO num_exp_div VALUES (6,7,'-.00113095617281538980');
291 INSERT INTO num_exp_add VALUES (6,8,'168782.57763026');
292 INSERT INTO num_exp_sub VALUES (6,8,'19020.57763026');
293 INSERT INTO num_exp_mul VALUES (6,8,'7031444034.53149906');
294 INSERT INTO num_exp_div VALUES (6,8,'1.25401073209839612184');
295 INSERT INTO num_exp_add VALUES (6,9,'-24832902.467417160');
296 INSERT INTO num_exp_sub VALUES (6,9,'25020705.622677680');
297 INSERT INTO num_exp_mul VALUES (6,9,'-2340666225110.29929521292692920');
298 INSERT INTO num_exp_div VALUES (6,9,'-.00376709254265256789');
299 INSERT INTO num_exp_add VALUES (7,0,'-83028485');
300 INSERT INTO num_exp_sub VALUES (7,0,'-83028485');
301 INSERT INTO num_exp_mul VALUES (7,0,'0');
302 INSERT INTO num_exp_div VALUES (7,0,'NaN');
303 INSERT INTO num_exp_add VALUES (7,1,'-83028485');
304 INSERT INTO num_exp_sub VALUES (7,1,'-83028485');
305 INSERT INTO num_exp_mul VALUES (7,1,'0');
306 INSERT INTO num_exp_div VALUES (7,1,'NaN');
307 INSERT INTO num_exp_add VALUES (7,2,'-117366977.215397047');
308 INSERT INTO num_exp_sub VALUES (7,2,'-48689992.784602953');
309 INSERT INTO num_exp_mul VALUES (7,2,'2851072985828710.485883795');
310 INSERT INTO num_exp_div VALUES (7,2,'2.41794207151503385700');
311 INSERT INTO num_exp_add VALUES (7,3,'-83028480.69');
312 INSERT INTO num_exp_sub VALUES (7,3,'-83028489.31');
313 INSERT INTO num_exp_mul VALUES (7,3,'-357852770.35');
314 INSERT INTO num_exp_div VALUES (7,3,'-19264149.65197215777262180974');
315 INSERT INTO num_exp_add VALUES (7,4,'-75229023.5881');
316 INSERT INTO num_exp_sub VALUES (7,4,'-90827946.4119');
317 INSERT INTO num_exp_mul VALUES (7,4,'-647577464846017.9715');
318 INSERT INTO num_exp_div VALUES (7,4,'-10.64541262725136247686');
319 INSERT INTO num_exp_add VALUES (7,5,'-83012087.961509');
320 INSERT INTO num_exp_sub VALUES (7,5,'-83044882.038491');
321 INSERT INTO num_exp_mul VALUES (7,5,'-1361421264394.416135');
322 INSERT INTO num_exp_div VALUES (7,5,'-5063.62688881730941836574');
323 INSERT INTO num_exp_add VALUES (7,6,'-82934583.42236974');
324 INSERT INTO num_exp_sub VALUES (7,6,'-83122386.57763026');
325 INSERT INTO num_exp_mul VALUES (7,6,'-7796505729750.37795610');
326 INSERT INTO num_exp_div VALUES (7,6,'-884.20756174009028770294');
327 INSERT INTO num_exp_add VALUES (7,7,'-166056970');
328 INSERT INTO num_exp_sub VALUES (7,7,'0');
329 INSERT INTO num_exp_mul VALUES (7,7,'6893729321395225');
330 INSERT INTO num_exp_div VALUES (7,7,'1.00000000000000000000');
331 INSERT INTO num_exp_add VALUES (7,8,'-82953604');
332 INSERT INTO num_exp_sub VALUES (7,8,'-83103366');
333 INSERT INTO num_exp_mul VALUES (7,8,'-6217255985285');
334 INSERT INTO num_exp_div VALUES (7,8,'-1108.80577182462841041118');
335 INSERT INTO num_exp_add VALUES (7,9,'-107955289.045047420');
336 INSERT INTO num_exp_sub VALUES (7,9,'-58101680.954952580');
337 INSERT INTO num_exp_mul VALUES (7,9,'2069634775752159.035758700');
338 INSERT INTO num_exp_div VALUES (7,9,'3.33089171198810413382');
339 INSERT INTO num_exp_add VALUES (8,0,'74881');
340 INSERT INTO num_exp_sub VALUES (8,0,'74881');
341 INSERT INTO num_exp_mul VALUES (8,0,'0');
342 INSERT INTO num_exp_div VALUES (8,0,'NaN');
343 INSERT INTO num_exp_add VALUES (8,1,'74881');
344 INSERT INTO num_exp_sub VALUES (8,1,'74881');
345 INSERT INTO num_exp_mul VALUES (8,1,'0');
346 INSERT INTO num_exp_div VALUES (8,1,'NaN');
347 INSERT INTO num_exp_add VALUES (8,2,'-34263611.215397047');
348 INSERT INTO num_exp_sub VALUES (8,2,'34413373.215397047');
349 INSERT INTO num_exp_mul VALUES (8,2,'-2571300635581.146276407');
350 INSERT INTO num_exp_div VALUES (8,2,'-.00218067233500788615');
351 INSERT INTO num_exp_add VALUES (8,3,'74885.31');
352 INSERT INTO num_exp_sub VALUES (8,3,'74876.69');
353 INSERT INTO num_exp_mul VALUES (8,3,'322737.11');
354 INSERT INTO num_exp_div VALUES (8,3,'17373.78190255220417633410');
355 INSERT INTO num_exp_add VALUES (8,4,'7874342.4119');
356 INSERT INTO num_exp_sub VALUES (8,4,'-7724580.4119');
357 INSERT INTO num_exp_mul VALUES (8,4,'584031469984.4839');
358 INSERT INTO num_exp_div VALUES (8,4,'.00960079113741758956');
359 INSERT INTO num_exp_add VALUES (8,5,'91278.038491');
360 INSERT INTO num_exp_sub VALUES (8,5,'58483.961509');
361 INSERT INTO num_exp_mul VALUES (8,5,'1227826639.244571');
362 INSERT INTO num_exp_div VALUES (8,5,'4.56673929509287019456');
363 INSERT INTO num_exp_add VALUES (8,6,'168782.57763026');
364 INSERT INTO num_exp_sub VALUES (8,6,'-19020.57763026');
365 INSERT INTO num_exp_mul VALUES (8,6,'7031444034.53149906');
366 INSERT INTO num_exp_div VALUES (8,6,'.79744134113322314424');
367 INSERT INTO num_exp_add VALUES (8,7,'-82953604');
368 INSERT INTO num_exp_sub VALUES (8,7,'83103366');
369 INSERT INTO num_exp_mul VALUES (8,7,'-6217255985285');
370 INSERT INTO num_exp_div VALUES (8,7,'-.00090187120721280172');
371 INSERT INTO num_exp_add VALUES (8,8,'149762');
372 INSERT INTO num_exp_sub VALUES (8,8,'0');
373 INSERT INTO num_exp_mul VALUES (8,8,'5607164161');
374 INSERT INTO num_exp_div VALUES (8,8,'1.00000000000000000000');
375 INSERT INTO num_exp_add VALUES (8,9,'-24851923.045047420');
376 INSERT INTO num_exp_sub VALUES (8,9,'25001685.045047420');
377 INSERT INTO num_exp_mul VALUES (8,9,'-1866544013697.195857020');
378 INSERT INTO num_exp_div VALUES (8,9,'-.00300403532938582735');
379 INSERT INTO num_exp_add VALUES (9,0,'-24926804.045047420');
380 INSERT INTO num_exp_sub VALUES (9,0,'-24926804.045047420');
381 INSERT INTO num_exp_mul VALUES (9,0,'0');
382 INSERT INTO num_exp_div VALUES (9,0,'NaN');
383 INSERT INTO num_exp_add VALUES (9,1,'-24926804.045047420');
384 INSERT INTO num_exp_sub VALUES (9,1,'-24926804.045047420');
385 INSERT INTO num_exp_mul VALUES (9,1,'0');
386 INSERT INTO num_exp_div VALUES (9,1,'NaN');
387 INSERT INTO num_exp_add VALUES (9,2,'-59265296.260444467');
388 INSERT INTO num_exp_sub VALUES (9,2,'9411688.170349627');
389 INSERT INTO num_exp_mul VALUES (9,2,'855948866655588.453741509242968740');
390 INSERT INTO num_exp_div VALUES (9,2,'.72591434384152961526');
391 INSERT INTO num_exp_add VALUES (9,3,'-24926799.735047420');
392 INSERT INTO num_exp_sub VALUES (9,3,'-24926808.355047420');
393 INSERT INTO num_exp_mul VALUES (9,3,'-107434525.43415438020');
394 INSERT INTO num_exp_div VALUES (9,3,'-5783481.21694835730858468677');
395 INSERT INTO num_exp_add VALUES (9,4,'-17127342.633147420');
396 INSERT INTO num_exp_sub VALUES (9,4,'-32726265.456947420');
397 INSERT INTO num_exp_mul VALUES (9,4,'-194415646271340.1815956522980');
398 INSERT INTO num_exp_div VALUES (9,4,'-3.19596478892958416484');
399 INSERT INTO num_exp_add VALUES (9,5,'-24910407.006556420');
400 INSERT INTO num_exp_sub VALUES (9,5,'-24943201.083538420');
401 INSERT INTO num_exp_mul VALUES (9,5,'-408725765384.257043660243220');
402 INSERT INTO num_exp_div VALUES (9,5,'-1520.20159364322004505807');
403 INSERT INTO num_exp_add VALUES (9,6,'-24832902.467417160');
404 INSERT INTO num_exp_sub VALUES (9,6,'-25020705.622677680');
405 INSERT INTO num_exp_mul VALUES (9,6,'-2340666225110.29929521292692920');
406 INSERT INTO num_exp_div VALUES (9,6,'-265.45671195426965751280');
407 INSERT INTO num_exp_add VALUES (9,7,'-107955289.045047420');
408 INSERT INTO num_exp_sub VALUES (9,7,'58101680.954952580');
409 INSERT INTO num_exp_mul VALUES (9,7,'2069634775752159.035758700');
410 INSERT INTO num_exp_div VALUES (9,7,'.30021990699995814689');
411 INSERT INTO num_exp_add VALUES (9,8,'-24851923.045047420');
412 INSERT INTO num_exp_sub VALUES (9,8,'-25001685.045047420');
413 INSERT INTO num_exp_mul VALUES (9,8,'-1866544013697.195857020');
414 INSERT INTO num_exp_div VALUES (9,8,'-332.88556569820675471748');
415 INSERT INTO num_exp_add VALUES (9,9,'-49853608.090094840');
416 INSERT INTO num_exp_sub VALUES (9,9,'0');
417 INSERT INTO num_exp_mul VALUES (9,9,'621345559900192.420120630048656400');
418 INSERT INTO num_exp_div VALUES (9,9,'1.00000000000000000000');
421 INSERT INTO num_exp_sqrt VALUES (0,'0');
422 INSERT INTO num_exp_sqrt VALUES (1,'0');
423 INSERT INTO num_exp_sqrt VALUES (2,'5859.90547836712524903505');
424 INSERT INTO num_exp_sqrt VALUES (3,'2.07605394920266944396');
425 INSERT INTO num_exp_sqrt VALUES (4,'2792.75158435189147418923');
426 INSERT INTO num_exp_sqrt VALUES (5,'128.05092147657509145473');
427 INSERT INTO num_exp_sqrt VALUES (6,'306.43364311096782703406');
428 INSERT INTO num_exp_sqrt VALUES (7,'9111.99676251039939975230');
429 INSERT INTO num_exp_sqrt VALUES (8,'273.64392922189960397542');
430 INSERT INTO num_exp_sqrt VALUES (9,'4992.67503899937593364766');
433 INSERT INTO num_exp_ln VALUES (0,'NaN');
434 INSERT INTO num_exp_ln VALUES (1,'NaN');
435 INSERT INTO num_exp_ln VALUES (2,'17.35177750493897715514');
436 INSERT INTO num_exp_ln VALUES (3,'1.46093790411565641971');
437 INSERT INTO num_exp_ln VALUES (4,'15.86956523951936572464');
438 INSERT INTO num_exp_ln VALUES (5,'9.70485601768871834038');
439 INSERT INTO num_exp_ln VALUES (6,'11.45000246622944403127');
440 INSERT INTO num_exp_ln VALUES (7,'18.23469429965478772991');
441 INSERT INTO num_exp_ln VALUES (8,'11.22365546576315513668');
442 INSERT INTO num_exp_ln VALUES (9,'17.03145425013166006962');
445 INSERT INTO num_exp_log10 VALUES (0,'NaN');
446 INSERT INTO num_exp_log10 VALUES (1,'NaN');
447 INSERT INTO num_exp_log10 VALUES (2,'7.53578122160797276459');
448 INSERT INTO num_exp_log10 VALUES (3,'.63447727016073160075');
449 INSERT INTO num_exp_log10 VALUES (4,'6.89206461372691743345');
450 INSERT INTO num_exp_log10 VALUES (5,'4.21476541614777768626');
451 INSERT INTO num_exp_log10 VALUES (6,'4.97267288886207207671');
452 INSERT INTO num_exp_log10 VALUES (7,'7.91922711353275546914');
453 INSERT INTO num_exp_log10 VALUES (8,'4.87437163556421004138');
454 INSERT INTO num_exp_log10 VALUES (9,'7.39666659961986567059');
457 INSERT INTO num_exp_power_10_ln VALUES (0,'NaN');
458 INSERT INTO num_exp_power_10_ln VALUES (1,'NaN');
459 INSERT INTO num_exp_power_10_ln VALUES (2,'224790267919917955.13261618583642653184');
460 INSERT INTO num_exp_power_10_ln VALUES (3,'28.90266599445155957393');
461 INSERT INTO num_exp_power_10_ln VALUES (4,'7405685069594999.07733999469386277636');
462 INSERT INTO num_exp_power_10_ln VALUES (5,'5068226527.32127265408584640098');
463 INSERT INTO num_exp_power_10_ln VALUES (6,'281839893606.99372343357047819067');
464 INSERT INTO num_exp_power_10_ln VALUES (7,'1716699575118597095.42330819910640247627');
465 INSERT INTO num_exp_power_10_ln VALUES (8,'167361463828.07491320069016125952');
466 INSERT INTO num_exp_power_10_ln VALUES (9,'107511333880052007.04141124673540337457');
469 INSERT INTO num_data VALUES (0, '0');
470 INSERT INTO num_data VALUES (1, '0');
471 INSERT INTO num_data VALUES (2, '-34338492.215397047');
472 INSERT INTO num_data VALUES (3, '4.31');
473 INSERT INTO num_data VALUES (4, '7799461.4119');
474 INSERT INTO num_data VALUES (5, '16397.038491');
475 INSERT INTO num_data VALUES (6, '93901.57763026');
476 INSERT INTO num_data VALUES (7, '-83028485');
477 INSERT INTO num_data VALUES (8, '74881');
478 INSERT INTO num_data VALUES (9, '-24926804.045047420');
480 -- ******************************
481 -- * Create indices for faster checks
482 -- ******************************
483 CREATE UNIQUE INDEX num_exp_add_idx ON num_exp_add (id1, id2);
484 CREATE UNIQUE INDEX num_exp_sub_idx ON num_exp_sub (id1, id2);
485 CREATE UNIQUE INDEX num_exp_div_idx ON num_exp_div (id1, id2);
486 CREATE UNIQUE INDEX num_exp_mul_idx ON num_exp_mul (id1, id2);
487 CREATE UNIQUE INDEX num_exp_sqrt_idx ON num_exp_sqrt (id);
488 CREATE UNIQUE INDEX num_exp_ln_idx ON num_exp_ln (id);
489 CREATE UNIQUE INDEX num_exp_log10_idx ON num_exp_log10 (id);
490 CREATE UNIQUE INDEX num_exp_power_10_ln_idx ON num_exp_power_10_ln (id);
491 VACUUM ANALYZE num_exp_add;
492 VACUUM ANALYZE num_exp_sub;
493 VACUUM ANALYZE num_exp_div;
494 VACUUM ANALYZE num_exp_mul;
495 VACUUM ANALYZE num_exp_sqrt;
496 VACUUM ANALYZE num_exp_ln;
497 VACUUM ANALYZE num_exp_log10;
498 VACUUM ANALYZE num_exp_power_10_ln;
499 -- ******************************
500 -- * Now check the behaviour of the NUMERIC type
501 -- ******************************
502 -- ******************************
504 -- ******************************
505 DELETE FROM num_result;
506 INSERT INTO num_result SELECT t1.id, t2.id, t1.val + t2.val
507 FROM num_data t1, num_data t2;
508 SELECT t1.id1, t1.id2, t1.result, t2.expected
509 FROM num_result t1, num_exp_add t2
510 WHERE t1.id1 = t2.id1 AND t1.id2 = t2.id2
511 AND t1.result != t2.expected;
512 id1 | id2 | result | expected
513 -----+-----+--------+----------
516 DELETE FROM num_result;
517 INSERT INTO num_result SELECT t1.id, t2.id, round(t1.val + t2.val, 10)
518 FROM num_data t1, num_data t2;
519 SELECT t1.id1, t1.id2, t1.result, round(t2.expected, 10) as expected
520 FROM num_result t1, num_exp_add t2
521 WHERE t1.id1 = t2.id1 AND t1.id2 = t2.id2
522 AND t1.result != round(t2.expected, 10);
523 id1 | id2 | result | expected
524 -----+-----+--------+----------
527 -- ******************************
528 -- * Subtraction check
529 -- ******************************
530 DELETE FROM num_result;
531 INSERT INTO num_result SELECT t1.id, t2.id, t1.val - t2.val
532 FROM num_data t1, num_data t2;
533 SELECT t1.id1, t1.id2, t1.result, t2.expected
534 FROM num_result t1, num_exp_sub t2
535 WHERE t1.id1 = t2.id1 AND t1.id2 = t2.id2
536 AND t1.result != t2.expected;
537 id1 | id2 | result | expected
538 -----+-----+--------+----------
541 DELETE FROM num_result;
542 INSERT INTO num_result SELECT t1.id, t2.id, round(t1.val - t2.val, 40)
543 FROM num_data t1, num_data t2;
544 SELECT t1.id1, t1.id2, t1.result, round(t2.expected, 40)
545 FROM num_result t1, num_exp_sub t2
546 WHERE t1.id1 = t2.id1 AND t1.id2 = t2.id2
547 AND t1.result != round(t2.expected, 40);
548 id1 | id2 | result | round
549 -----+-----+--------+-------
552 -- ******************************
554 -- ******************************
555 DELETE FROM num_result;
556 INSERT INTO num_result SELECT t1.id, t2.id, t1.val * t2.val
557 FROM num_data t1, num_data t2;
558 SELECT t1.id1, t1.id2, t1.result, t2.expected
559 FROM num_result t1, num_exp_mul t2
560 WHERE t1.id1 = t2.id1 AND t1.id2 = t2.id2
561 AND t1.result != t2.expected;
562 id1 | id2 | result | expected
563 -----+-----+--------+----------
566 DELETE FROM num_result;
567 INSERT INTO num_result SELECT t1.id, t2.id, round(t1.val * t2.val, 30)
568 FROM num_data t1, num_data t2;
569 SELECT t1.id1, t1.id2, t1.result, round(t2.expected, 30) as expected
570 FROM num_result t1, num_exp_mul t2
571 WHERE t1.id1 = t2.id1 AND t1.id2 = t2.id2
572 AND t1.result != round(t2.expected, 30);
573 id1 | id2 | result | expected
574 -----+-----+--------+----------
577 -- ******************************
579 -- ******************************
580 DELETE FROM num_result;
581 INSERT INTO num_result SELECT t1.id, t2.id, t1.val / t2.val
582 FROM num_data t1, num_data t2
583 WHERE t2.val != '0.0';
584 SELECT t1.id1, t1.id2, t1.result, t2.expected
585 FROM num_result t1, num_exp_div t2
586 WHERE t1.id1 = t2.id1 AND t1.id2 = t2.id2
587 AND t1.result != t2.expected;
588 id1 | id2 | result | expected
589 -----+-----+--------+----------
592 DELETE FROM num_result;
593 INSERT INTO num_result SELECT t1.id, t2.id, round(t1.val / t2.val, 80)
594 FROM num_data t1, num_data t2
595 WHERE t2.val != '0.0';
596 SELECT t1.id1, t1.id2, t1.result, round(t2.expected, 80) as expected
597 FROM num_result t1, num_exp_div t2
598 WHERE t1.id1 = t2.id1 AND t1.id2 = t2.id2
599 AND t1.result != round(t2.expected, 80);
600 id1 | id2 | result | expected
601 -----+-----+--------+----------
604 -- ******************************
605 -- * Square root check
606 -- ******************************
607 DELETE FROM num_result;
608 INSERT INTO num_result SELECT id, 0, SQRT(ABS(val))
610 SELECT t1.id1, t1.result, t2.expected
611 FROM num_result t1, num_exp_sqrt t2
613 AND t1.result != t2.expected;
614 id1 | result | expected
615 -----+--------+----------
618 -- ******************************
619 -- * Natural logarithm check
620 -- ******************************
621 DELETE FROM num_result;
622 INSERT INTO num_result SELECT id, 0, LN(ABS(val))
625 SELECT t1.id1, t1.result, t2.expected
626 FROM num_result t1, num_exp_ln t2
628 AND t1.result != t2.expected;
629 id1 | result | expected
630 -----+--------+----------
633 -- ******************************
634 -- * Logarithm base 10 check
635 -- ******************************
636 DELETE FROM num_result;
637 INSERT INTO num_result SELECT id, 0, LOG(numeric '10', ABS(val))
640 SELECT t1.id1, t1.result, t2.expected
641 FROM num_result t1, num_exp_log10 t2
643 AND t1.result != t2.expected;
644 id1 | result | expected
645 -----+--------+----------
648 -- ******************************
649 -- * POWER(10, LN(value)) check
650 -- ******************************
651 DELETE FROM num_result;
652 INSERT INTO num_result SELECT id, 0, POWER(numeric '10', LN(ABS(round(val,200))))
655 SELECT t1.id1, t1.result, t2.expected
656 FROM num_result t1, num_exp_power_10_ln t2
658 AND t1.result != t2.expected;
659 id1 | result | expected
660 -----+--------+----------
663 -- ******************************
664 -- * Check behavior with Inf and NaN inputs. It's easiest to handle these
665 -- * separately from the num_data framework used above, because some input
666 -- * combinations will throw errors.
667 -- ******************************
669 (VALUES('0'::numeric),('1'),('-1'),('4.2'),('inf'),('-inf'),('nan'))
674 FROM v AS v1(x1), v AS v2(x2);
675 x1 | x2 | sum | diff | prod
676 -----------+-----------+-----------+-----------+-----------
680 0 | 4.2 | 4.2 | -4.2 | 0.0
681 0 | Infinity | Infinity | -Infinity | NaN
682 0 | -Infinity | -Infinity | Infinity | NaN
683 0 | NaN | NaN | NaN | NaN
687 1 | 4.2 | 5.2 | -3.2 | 4.2
688 1 | Infinity | Infinity | -Infinity | Infinity
689 1 | -Infinity | -Infinity | Infinity | -Infinity
690 1 | NaN | NaN | NaN | NaN
694 -1 | 4.2 | 3.2 | -5.2 | -4.2
695 -1 | Infinity | Infinity | -Infinity | -Infinity
696 -1 | -Infinity | -Infinity | Infinity | Infinity
697 -1 | NaN | NaN | NaN | NaN
698 4.2 | 0 | 4.2 | 4.2 | 0.0
699 4.2 | 1 | 5.2 | 3.2 | 4.2
700 4.2 | -1 | 3.2 | 5.2 | -4.2
701 4.2 | 4.2 | 8.4 | 0.0 | 17.64
702 4.2 | Infinity | Infinity | -Infinity | Infinity
703 4.2 | -Infinity | -Infinity | Infinity | -Infinity
704 4.2 | NaN | NaN | NaN | NaN
705 Infinity | 0 | Infinity | Infinity | NaN
706 Infinity | 1 | Infinity | Infinity | Infinity
707 Infinity | -1 | Infinity | Infinity | -Infinity
708 Infinity | 4.2 | Infinity | Infinity | Infinity
709 Infinity | Infinity | Infinity | NaN | Infinity
710 Infinity | -Infinity | NaN | Infinity | -Infinity
711 Infinity | NaN | NaN | NaN | NaN
712 -Infinity | 0 | -Infinity | -Infinity | NaN
713 -Infinity | 1 | -Infinity | -Infinity | -Infinity
714 -Infinity | -1 | -Infinity | -Infinity | Infinity
715 -Infinity | 4.2 | -Infinity | -Infinity | -Infinity
716 -Infinity | Infinity | NaN | -Infinity | -Infinity
717 -Infinity | -Infinity | -Infinity | NaN | Infinity
718 -Infinity | NaN | NaN | NaN | NaN
719 NaN | 0 | NaN | NaN | NaN
720 NaN | 1 | NaN | NaN | NaN
721 NaN | -1 | NaN | NaN | NaN
722 NaN | 4.2 | NaN | NaN | NaN
723 NaN | Infinity | NaN | NaN | NaN
724 NaN | -Infinity | NaN | NaN | NaN
725 NaN | NaN | NaN | NaN | NaN
729 (VALUES('0'::numeric),('1'),('-1'),('4.2'),('inf'),('-inf'),('nan'))
734 FROM v AS v1(x1), v AS v2(x2) WHERE x2 != 0;
735 x1 | x2 | quot | mod | div
736 -----------+-----------+-------------------------+------+-----------
737 0 | 1 | 0.00000000000000000000 | 0 | 0
738 1 | 1 | 1.00000000000000000000 | 0 | 1
739 -1 | 1 | -1.00000000000000000000 | 0 | -1
740 4.2 | 1 | 4.2000000000000000 | 0.2 | 4
741 Infinity | 1 | Infinity | NaN | Infinity
742 -Infinity | 1 | -Infinity | NaN | -Infinity
743 NaN | 1 | NaN | NaN | NaN
744 0 | -1 | 0.00000000000000000000 | 0 | 0
745 1 | -1 | -1.00000000000000000000 | 0 | -1
746 -1 | -1 | 1.00000000000000000000 | 0 | 1
747 4.2 | -1 | -4.2000000000000000 | 0.2 | -4
748 Infinity | -1 | -Infinity | NaN | -Infinity
749 -Infinity | -1 | Infinity | NaN | Infinity
750 NaN | -1 | NaN | NaN | NaN
751 0 | 4.2 | 0.00000000000000000000 | 0.0 | 0
752 1 | 4.2 | 0.23809523809523809524 | 1.0 | 0
753 -1 | 4.2 | -0.23809523809523809524 | -1.0 | 0
754 4.2 | 4.2 | 1.00000000000000000000 | 0.0 | 1
755 Infinity | 4.2 | Infinity | NaN | Infinity
756 -Infinity | 4.2 | -Infinity | NaN | -Infinity
757 NaN | 4.2 | NaN | NaN | NaN
758 0 | Infinity | 0 | 0 | 0
759 1 | Infinity | 0 | 1 | 0
760 -1 | Infinity | 0 | -1 | 0
761 4.2 | Infinity | 0 | 4.2 | 0
762 Infinity | Infinity | NaN | NaN | NaN
763 -Infinity | Infinity | NaN | NaN | NaN
764 NaN | Infinity | NaN | NaN | NaN
765 0 | -Infinity | 0 | 0 | 0
766 1 | -Infinity | 0 | 1 | 0
767 -1 | -Infinity | 0 | -1 | 0
768 4.2 | -Infinity | 0 | 4.2 | 0
769 Infinity | -Infinity | NaN | NaN | NaN
770 -Infinity | -Infinity | NaN | NaN | NaN
771 NaN | -Infinity | NaN | NaN | NaN
772 0 | NaN | NaN | NaN | NaN
773 1 | NaN | NaN | NaN | NaN
774 -1 | NaN | NaN | NaN | NaN
775 4.2 | NaN | NaN | NaN | NaN
776 Infinity | NaN | NaN | NaN | NaN
777 -Infinity | NaN | NaN | NaN | NaN
778 NaN | NaN | NaN | NaN | NaN
781 SELECT 'inf'::numeric / '0';
782 ERROR: division by zero
783 SELECT '-inf'::numeric / '0';
784 ERROR: division by zero
785 SELECT 'nan'::numeric / '0';
791 SELECT '0'::numeric / '0';
792 ERROR: division by zero
793 SELECT 'inf'::numeric % '0';
794 ERROR: division by zero
795 SELECT '-inf'::numeric % '0';
796 ERROR: division by zero
797 SELECT 'nan'::numeric % '0';
803 SELECT '0'::numeric % '0';
804 ERROR: division by zero
805 SELECT div('inf'::numeric, '0');
806 ERROR: division by zero
807 SELECT div('-inf'::numeric, '0');
808 ERROR: division by zero
809 SELECT div('nan'::numeric, '0');
815 SELECT div('0'::numeric, '0');
816 ERROR: division by zero
818 (VALUES('0'::numeric),('1'),('-1'),('4.2'),('-7.777'),('inf'),('-inf'),('nan'))
819 SELECT x, -x as minusx, abs(x), floor(x), ceil(x), sign(x), numeric_inc(x) as inc
821 x | minusx | abs | floor | ceil | sign | inc
822 -----------+-----------+----------+-----------+-----------+------+-----------
823 0 | 0 | 0 | 0 | 0 | 0 | 1
824 1 | -1 | 1 | 1 | 1 | 1 | 2
825 -1 | 1 | 1 | -1 | -1 | -1 | 0
826 4.2 | -4.2 | 4.2 | 4 | 5 | 1 | 5.2
827 -7.777 | 7.777 | 7.777 | -8 | -7 | -1 | -6.777
828 Infinity | -Infinity | Infinity | Infinity | Infinity | 1 | Infinity
829 -Infinity | Infinity | Infinity | -Infinity | -Infinity | -1 | -Infinity
830 NaN | NaN | NaN | NaN | NaN | NaN | NaN
834 (VALUES('0'::numeric),('1'),('-1'),('4.2'),('-7.777'),('inf'),('-inf'),('nan'))
835 SELECT x, round(x), round(x,1) as round1, trunc(x), trunc(x,1) as trunc1
837 x | round | round1 | trunc | trunc1
838 -----------+-----------+-----------+-----------+-----------
839 0 | 0 | 0.0 | 0 | 0.0
840 1 | 1 | 1.0 | 1 | 1.0
841 -1 | -1 | -1.0 | -1 | -1.0
842 4.2 | 4 | 4.2 | 4 | 4.2
843 -7.777 | -8 | -7.8 | -7 | -7.7
844 Infinity | Infinity | Infinity | Infinity | Infinity
845 -Infinity | -Infinity | -Infinity | -Infinity | -Infinity
846 NaN | NaN | NaN | NaN | NaN
849 -- the large values fall into the numeric abbreviation code's maximal classes
851 (VALUES('0'::numeric),('1'),('-1'),('4.2'),('-7.777'),('1e340'),('-1e340'),
852 ('inf'),('-inf'),('nan'),
853 ('inf'),('-inf'),('nan'))
854 SELECT substring(x::text, 1, 32)
857 ----------------------------------
860 -1000000000000000000000000000000
866 10000000000000000000000000000000
874 (VALUES('0'::numeric),('1'),('4.2'),('inf'),('nan'))
878 ----------+-------------------
879 0 | 0.000000000000000
880 1 | 1.000000000000000
881 4.2 | 2.049390153191920
886 SELECT sqrt('-1'::numeric);
887 ERROR: cannot take square root of a negative number
888 SELECT sqrt('-inf'::numeric);
889 ERROR: cannot take square root of a negative number
891 (VALUES('1'::numeric),('4.2'),('inf'),('nan'))
898 ----------+--------------------+--------------------+--------------------
899 1 | 0.0000000000000000 | 0.0000000000000000 | 0.0000000000000000
900 4.2 | 0.6232492903979005 | 0.6232492903979005 | 1.4350845252893226
901 Infinity | Infinity | Infinity | Infinity
902 NaN | NaN | NaN | NaN
905 SELECT ln('0'::numeric);
906 ERROR: cannot take logarithm of zero
907 SELECT ln('-1'::numeric);
908 ERROR: cannot take logarithm of a negative number
909 SELECT ln('-inf'::numeric);
910 ERROR: cannot take logarithm of a negative number
912 (VALUES('2'::numeric),('4.2'),('inf'),('nan'))
915 FROM v AS v1(x1), v AS v2(x2);
917 ----------+----------+--------------------
918 2 | 2 | 1.0000000000000000
919 2 | 4.2 | 2.0703893278913979
920 2 | Infinity | Infinity
922 4.2 | 2 | 0.4830009440873890
923 4.2 | 4.2 | 1.0000000000000000
924 4.2 | Infinity | Infinity
928 Infinity | Infinity | NaN
936 SELECT log('0'::numeric, '10');
937 ERROR: cannot take logarithm of zero
938 SELECT log('10'::numeric, '0');
939 ERROR: cannot take logarithm of zero
940 SELECT log('-inf'::numeric, '10');
941 ERROR: cannot take logarithm of a negative number
942 SELECT log('10'::numeric, '-inf');
943 ERROR: cannot take logarithm of a negative number
944 SELECT log('inf'::numeric, '0');
945 ERROR: cannot take logarithm of zero
946 SELECT log('inf'::numeric, '-inf');
947 ERROR: cannot take logarithm of a negative number
948 SELECT log('-inf'::numeric, 'inf');
949 ERROR: cannot take logarithm of a negative number
951 (VALUES('0'::numeric),('1'),('2'),('4.2'),('inf'),('nan'))
954 FROM v AS v1(x1), v AS v2(x2) WHERE x1 != 0 OR x2 >= 0;
956 ----------+----------+--------------------
957 0 | 0 | 1.0000000000000000
958 0 | 1 | 0.0000000000000000
959 0 | 2 | 0.0000000000000000
960 0 | 4.2 | 0.0000000000000000
963 1 | 0 | 1.0000000000000000
964 1 | 1 | 1.0000000000000000
965 1 | 2 | 1.0000000000000000
966 1 | 4.2 | 1.0000000000000000
969 2 | 0 | 1.0000000000000000
970 2 | 1 | 2.0000000000000000
971 2 | 2 | 4.0000000000000000
972 2 | 4.2 | 18.379173679952560
973 2 | Infinity | Infinity
975 4.2 | 0 | 1.0000000000000000
976 4.2 | 1 | 4.2000000000000000
977 4.2 | 2 | 17.640000000000000
978 4.2 | 4.2 | 414.61691860129675
979 4.2 | Infinity | Infinity
982 Infinity | 1 | Infinity
983 Infinity | 2 | Infinity
984 Infinity | 4.2 | Infinity
985 Infinity | Infinity | Infinity
995 SELECT power('0'::numeric, '-1');
996 ERROR: zero raised to a negative power is undefined
997 SELECT power('0'::numeric, '-inf');
998 ERROR: zero raised to a negative power is undefined
999 SELECT power('-1'::numeric, 'inf');
1005 SELECT power('-2'::numeric, '3');
1007 ---------------------
1011 SELECT power('-2'::numeric, '3.3');
1012 ERROR: a negative number raised to a non-integer power yields a complex result
1013 SELECT power('-2'::numeric, '-1');
1015 ---------------------
1019 SELECT power('-2'::numeric, '-1.5');
1020 ERROR: a negative number raised to a non-integer power yields a complex result
1021 SELECT power('-2'::numeric, 'inf');
1027 SELECT power('-2'::numeric, '-inf');
1033 SELECT power('inf'::numeric, '-2');
1039 SELECT power('inf'::numeric, '-inf');
1045 SELECT power('-inf'::numeric, '2');
1051 SELECT power('-inf'::numeric, '3');
1057 SELECT power('-inf'::numeric, '4.5');
1058 ERROR: a negative number raised to a non-integer power yields a complex result
1059 SELECT power('-inf'::numeric, '-2');
1065 SELECT power('-inf'::numeric, '-3');
1071 SELECT power('-inf'::numeric, '0');
1077 SELECT power('-inf'::numeric, 'inf');
1083 SELECT power('-inf'::numeric, '-inf');
1089 -- ******************************
1090 -- * miscellaneous checks for things that have been broken in the past...
1091 -- ******************************
1092 -- numeric AVG used to fail on some platforms
1093 SELECT AVG(val) FROM num_data;
1095 ------------------------
1096 -13430913.592242320700
1099 SELECT MAX(val) FROM num_data;
1101 --------------------
1105 SELECT MIN(val) FROM num_data;
1107 ----------------------
1108 -83028485.0000000000
1111 SELECT STDDEV(val) FROM num_data;
1113 -------------------------------
1114 27791203.28758835329805617386
1117 SELECT VARIANCE(val) FROM num_data;
1119 --------------------------------------
1120 772350980172061.69659105821915863601
1123 -- Check for appropriate rounding and overflow
1124 CREATE TABLE fract_only (id int, val numeric(4,4));
1125 INSERT INTO fract_only VALUES (1, '0.0');
1126 INSERT INTO fract_only VALUES (2, '0.1');
1127 INSERT INTO fract_only VALUES (3, '1.0'); -- should fail
1128 ERROR: numeric field overflow
1129 DETAIL: A field with precision 4, scale 4 must round to an absolute value less than 1.
1130 INSERT INTO fract_only VALUES (4, '-0.9999');
1131 INSERT INTO fract_only VALUES (5, '0.99994');
1132 INSERT INTO fract_only VALUES (6, '0.99995'); -- should fail
1133 ERROR: numeric field overflow
1134 DETAIL: A field with precision 4, scale 4 must round to an absolute value less than 1.
1135 INSERT INTO fract_only VALUES (7, '0.00001');
1136 INSERT INTO fract_only VALUES (8, '0.00017');
1137 INSERT INTO fract_only VALUES (9, 'NaN');
1138 INSERT INTO fract_only VALUES (10, 'Inf'); -- should fail
1139 ERROR: numeric field overflow
1140 DETAIL: A field with precision 4, scale 4 cannot hold an infinite value.
1141 INSERT INTO fract_only VALUES (11, '-Inf'); -- should fail
1142 ERROR: numeric field overflow
1143 DETAIL: A field with precision 4, scale 4 cannot hold an infinite value.
1144 SELECT * FROM fract_only;
1156 DROP TABLE fract_only;
1157 -- Check conversion to integers
1158 SELECT (-9223372036854775808.5)::int8; -- should fail
1159 ERROR: bigint out of range
1160 SELECT (-9223372036854775808.4)::int8; -- ok
1162 ----------------------
1163 -9223372036854775808
1166 SELECT 9223372036854775807.4::int8; -- ok
1168 ---------------------
1172 SELECT 9223372036854775807.5::int8; -- should fail
1173 ERROR: bigint out of range
1174 SELECT (-2147483648.5)::int4; -- should fail
1175 ERROR: integer out of range
1176 SELECT (-2147483648.4)::int4; -- ok
1182 SELECT 2147483647.4::int4; -- ok
1188 SELECT 2147483647.5::int4; -- should fail
1189 ERROR: integer out of range
1190 SELECT (-32768.5)::int2; -- should fail
1191 ERROR: smallint out of range
1192 SELECT (-32768.4)::int2; -- ok
1198 SELECT 32767.4::int2; -- ok
1204 SELECT 32767.5::int2; -- should fail
1205 ERROR: smallint out of range
1206 -- Check inf/nan conversion behavior
1207 SELECT 'NaN'::float8::numeric;
1213 SELECT 'Infinity'::float8::numeric;
1219 SELECT '-Infinity'::float8::numeric;
1225 SELECT 'NaN'::numeric::float8;
1231 SELECT 'Infinity'::numeric::float8;
1237 SELECT '-Infinity'::numeric::float8;
1243 SELECT 'NaN'::float4::numeric;
1249 SELECT 'Infinity'::float4::numeric;
1255 SELECT '-Infinity'::float4::numeric;
1261 SELECT 'NaN'::numeric::float4;
1267 SELECT 'Infinity'::numeric::float4;
1273 SELECT '-Infinity'::numeric::float4;
1279 SELECT '42'::int2::numeric;
1285 SELECT 'NaN'::numeric::int2;
1286 ERROR: cannot convert NaN to smallint
1287 SELECT 'Infinity'::numeric::int2;
1288 ERROR: cannot convert infinity to smallint
1289 SELECT '-Infinity'::numeric::int2;
1290 ERROR: cannot convert infinity to smallint
1291 SELECT 'NaN'::numeric::int4;
1292 ERROR: cannot convert NaN to integer
1293 SELECT 'Infinity'::numeric::int4;
1294 ERROR: cannot convert infinity to integer
1295 SELECT '-Infinity'::numeric::int4;
1296 ERROR: cannot convert infinity to integer
1297 SELECT 'NaN'::numeric::int8;
1298 ERROR: cannot convert NaN to bigint
1299 SELECT 'Infinity'::numeric::int8;
1300 ERROR: cannot convert infinity to bigint
1301 SELECT '-Infinity'::numeric::int8;
1302 ERROR: cannot convert infinity to bigint
1303 -- Simple check that ceil(), floor(), and round() work correctly
1304 CREATE TABLE ceil_floor_round (a numeric);
1305 INSERT INTO ceil_floor_round VALUES ('-5.5');
1306 INSERT INTO ceil_floor_round VALUES ('-5.499999');
1307 INSERT INTO ceil_floor_round VALUES ('9.5');
1308 INSERT INTO ceil_floor_round VALUES ('9.4999999');
1309 INSERT INTO ceil_floor_round VALUES ('0.0');
1310 INSERT INTO ceil_floor_round VALUES ('0.0000001');
1311 INSERT INTO ceil_floor_round VALUES ('-0.000001');
1312 SELECT a, ceil(a), ceiling(a), floor(a), round(a) FROM ceil_floor_round;
1313 a | ceil | ceiling | floor | round
1314 -----------+------+---------+-------+-------
1315 -5.5 | -5 | -5 | -6 | -6
1316 -5.499999 | -5 | -5 | -6 | -5
1317 9.5 | 10 | 10 | 9 | 10
1318 9.4999999 | 10 | 10 | 9 | 9
1320 0.0000001 | 1 | 1 | 0 | 0
1321 -0.000001 | 0 | 0 | -1 | 0
1324 DROP TABLE ceil_floor_round;
1325 -- Check rounding, it should round ties away from zero.
1327 round((-2.5 * 10 ^ i)::numeric, -i),
1328 round((-1.5 * 10 ^ i)::numeric, -i),
1329 round((-0.5 * 10 ^ i)::numeric, -i),
1330 round((0.5 * 10 ^ i)::numeric, -i),
1331 round((1.5 * 10 ^ i)::numeric, -i),
1332 round((2.5 * 10 ^ i)::numeric, -i)
1333 FROM generate_series(-5,5) AS t(i);
1334 pow | round | round | round | round | round | round
1335 -----+----------+----------+----------+---------+---------+---------
1336 -5 | -0.00003 | -0.00002 | -0.00001 | 0.00001 | 0.00002 | 0.00003
1337 -4 | -0.0003 | -0.0002 | -0.0001 | 0.0001 | 0.0002 | 0.0003
1338 -3 | -0.003 | -0.002 | -0.001 | 0.001 | 0.002 | 0.003
1339 -2 | -0.03 | -0.02 | -0.01 | 0.01 | 0.02 | 0.03
1340 -1 | -0.3 | -0.2 | -0.1 | 0.1 | 0.2 | 0.3
1341 0 | -3 | -2 | -1 | 1 | 2 | 3
1342 1 | -30 | -20 | -10 | 10 | 20 | 30
1343 2 | -300 | -200 | -100 | 100 | 200 | 300
1344 3 | -3000 | -2000 | -1000 | 1000 | 2000 | 3000
1345 4 | -30000 | -20000 | -10000 | 10000 | 20000 | 30000
1346 5 | -300000 | -200000 | -100000 | 100000 | 200000 | 300000
1349 -- Testing for width_bucket(). For convenience, we test both the
1350 -- numeric and float8 versions of the function in this file.
1352 SELECT width_bucket(5.0, 3.0, 4.0, 0);
1353 ERROR: count must be greater than zero
1354 SELECT width_bucket(5.0, 3.0, 4.0, -5);
1355 ERROR: count must be greater than zero
1356 SELECT width_bucket(3.5, 3.0, 3.0, 888);
1357 ERROR: lower bound cannot equal upper bound
1358 SELECT width_bucket(5.0::float8, 3.0::float8, 4.0::float8, 0);
1359 ERROR: count must be greater than zero
1360 SELECT width_bucket(5.0::float8, 3.0::float8, 4.0::float8, -5);
1361 ERROR: count must be greater than zero
1362 SELECT width_bucket(3.5::float8, 3.0::float8, 3.0::float8, 888);
1363 ERROR: lower bound cannot equal upper bound
1364 SELECT width_bucket('NaN', 3.0, 4.0, 888);
1365 ERROR: operand, lower bound, and upper bound cannot be NaN
1366 SELECT width_bucket(0::float8, 'NaN', 4.0::float8, 888);
1367 ERROR: operand, lower bound, and upper bound cannot be NaN
1368 SELECT width_bucket(2.0, 3.0, '-inf', 888);
1369 ERROR: lower and upper bounds must be finite
1370 SELECT width_bucket(0::float8, '-inf', 4.0::float8, 888);
1371 ERROR: lower and upper bounds must be finite
1373 CREATE TABLE width_bucket_test (operand_num numeric, operand_f8 float8);
1374 COPY width_bucket_test (operand_num) FROM stdin;
1375 UPDATE width_bucket_test SET operand_f8 = operand_num::float8;
1378 width_bucket(operand_num, 0, 10, 5) AS wb_1,
1379 width_bucket(operand_f8, 0, 10, 5) AS wb_1f,
1380 width_bucket(operand_num, 10, 0, 5) AS wb_2,
1381 width_bucket(operand_f8, 10, 0, 5) AS wb_2f,
1382 width_bucket(operand_num, 2, 8, 4) AS wb_3,
1383 width_bucket(operand_f8, 2, 8, 4) AS wb_3f,
1384 width_bucket(operand_num, 5.0, 5.5, 20) AS wb_4,
1385 width_bucket(operand_f8, 5.0, 5.5, 20) AS wb_4f,
1386 width_bucket(operand_num, -25, 25, 10) AS wb_5,
1387 width_bucket(operand_f8, -25, 25, 10) AS wb_5f
1388 FROM width_bucket_test;
1389 operand_num | wb_1 | wb_1f | wb_2 | wb_2f | wb_3 | wb_3f | wb_4 | wb_4f | wb_5 | wb_5f
1390 ------------------+------+-------+------+-------+------+-------+------+-------+------+-------
1391 -5.2 | 0 | 0 | 6 | 6 | 0 | 0 | 0 | 0 | 4 | 4
1392 -0.0000000001 | 0 | 0 | 6 | 6 | 0 | 0 | 0 | 0 | 5 | 5
1393 0.000000000001 | 1 | 1 | 5 | 5 | 0 | 0 | 0 | 0 | 6 | 6
1394 1 | 1 | 1 | 5 | 5 | 0 | 0 | 0 | 0 | 6 | 6
1395 1.99999999999999 | 1 | 1 | 5 | 5 | 0 | 0 | 0 | 0 | 6 | 6
1396 2 | 2 | 2 | 5 | 5 | 1 | 1 | 0 | 0 | 6 | 6
1397 2.00000000000001 | 2 | 2 | 4 | 4 | 1 | 1 | 0 | 0 | 6 | 6
1398 3 | 2 | 2 | 4 | 4 | 1 | 1 | 0 | 0 | 6 | 6
1399 4 | 3 | 3 | 4 | 4 | 2 | 2 | 0 | 0 | 6 | 6
1400 4.5 | 3 | 3 | 3 | 3 | 2 | 2 | 0 | 0 | 6 | 6
1401 5 | 3 | 3 | 3 | 3 | 3 | 3 | 1 | 1 | 7 | 7
1402 5.5 | 3 | 3 | 3 | 3 | 3 | 3 | 21 | 21 | 7 | 7
1403 6 | 4 | 4 | 3 | 3 | 3 | 3 | 21 | 21 | 7 | 7
1404 7 | 4 | 4 | 2 | 2 | 4 | 4 | 21 | 21 | 7 | 7
1405 8 | 5 | 5 | 2 | 2 | 5 | 5 | 21 | 21 | 7 | 7
1406 9 | 5 | 5 | 1 | 1 | 5 | 5 | 21 | 21 | 7 | 7
1407 9.99999999999999 | 5 | 5 | 1 | 1 | 5 | 5 | 21 | 21 | 7 | 7
1408 10 | 6 | 6 | 1 | 1 | 5 | 5 | 21 | 21 | 8 | 8
1409 10.0000000000001 | 6 | 6 | 0 | 0 | 5 | 5 | 21 | 21 | 8 | 8
1412 -- Check positive and negative infinity: we require
1413 -- finite bucket bounds, but allow an infinite operand
1414 SELECT width_bucket(0.0::numeric, 'Infinity'::numeric, 5, 10); -- error
1415 ERROR: lower and upper bounds must be finite
1416 SELECT width_bucket(0.0::numeric, 5, '-Infinity'::numeric, 20); -- error
1417 ERROR: lower and upper bounds must be finite
1418 SELECT width_bucket('Infinity'::numeric, 1, 10, 10),
1419 width_bucket('-Infinity'::numeric, 1, 10, 10);
1420 width_bucket | width_bucket
1421 --------------+--------------
1425 SELECT width_bucket(0.0::float8, 'Infinity'::float8, 5, 10); -- error
1426 ERROR: lower and upper bounds must be finite
1427 SELECT width_bucket(0.0::float8, 5, '-Infinity'::float8, 20); -- error
1428 ERROR: lower and upper bounds must be finite
1429 SELECT width_bucket('Infinity'::float8, 1, 10, 10),
1430 width_bucket('-Infinity'::float8, 1, 10, 10);
1431 width_bucket | width_bucket
1432 --------------+--------------
1436 DROP TABLE width_bucket_test;
1437 -- Simple test for roundoff error when results should be exact
1438 SELECT x, width_bucket(x::float8, 10, 100, 9) as flt,
1439 width_bucket(x::numeric, 10, 100, 9) as num
1440 FROM generate_series(0, 110, 10) x;
1457 SELECT x, width_bucket(x::float8, 100, 10, 9) as flt,
1458 width_bucket(x::numeric, 100, 10, 9) as num
1459 FROM generate_series(0, 110, 10) x;
1476 -- Another roundoff-error hazard
1477 SELECT width_bucket(0, -1e100::numeric, 1, 10);
1483 SELECT width_bucket(0, -1e100::float8, 1, 10);
1489 SELECT width_bucket(1, 1e100::numeric, 0, 10);
1495 SELECT width_bucket(1, 1e100::float8, 0, 10);
1501 -- Check cases that could trigger overflow or underflow within the calculation
1502 SELECT oper, low, high, cnt, width_bucket(oper, low, high, cnt)
1504 (SELECT 1.797e+308::float8 AS big, 5e-324::float8 AS tiny) as v,
1506 (10.5::float8, -big, big, 1),
1507 (10.5::float8, -big, big, 2),
1508 (10.5::float8, -big, big, 3),
1509 (big / 4, -big / 2, big / 2, 10),
1510 (10.5::float8, big, -big, 1),
1511 (10.5::float8, big, -big, 2),
1512 (10.5::float8, big, -big, 3),
1513 (big / 4, big / 2, -big / 2, 10),
1516 (0, 0, 1, 2147483647),
1517 (1, 1, 0, 2147483647)
1518 ) as sample(oper, low, high, cnt);
1519 oper | low | high | cnt | width_bucket
1520 -------------+-------------+-------------+------------+--------------
1521 10.5 | -1.797e+308 | 1.797e+308 | 1 | 1
1522 10.5 | -1.797e+308 | 1.797e+308 | 2 | 2
1523 10.5 | -1.797e+308 | 1.797e+308 | 3 | 2
1524 4.4925e+307 | -8.985e+307 | 8.985e+307 | 10 | 8
1525 10.5 | 1.797e+308 | -1.797e+308 | 1 | 1
1526 10.5 | 1.797e+308 | -1.797e+308 | 2 | 2
1527 10.5 | 1.797e+308 | -1.797e+308 | 3 | 2
1528 4.4925e+307 | 8.985e+307 | -8.985e+307 | 10 | 3
1529 0 | 0 | 5e-324 | 4 | 1
1530 5e-324 | 0 | 5e-324 | 4 | 5
1531 0 | 0 | 1 | 2147483647 | 1
1532 1 | 1 | 0 | 2147483647 | 1
1535 -- These fail because the result would be out of int32 range:
1536 SELECT width_bucket(1::float8, 0, 1, 2147483647);
1537 ERROR: integer out of range
1538 SELECT width_bucket(0::float8, 1, 0, 2147483647);
1539 ERROR: integer out of range
1543 SELECT to_char(val, '9G999G999G999G999G999')
1546 ------------------------
1559 SELECT to_char(val, '9G999G999G999G999G999D999G999G999G999G999')
1562 --------------------------------------------
1563 .000,000,000,000,000
1564 .000,000,000,000,000
1565 -34,338,492.215,397,047,000,000
1566 4.310,000,000,000,000
1567 7,799,461.411,900,000,000,000
1568 16,397.038,491,000,000,000
1569 93,901.577,630,260,000,000
1570 -83,028,485.000,000,000,000,000
1571 74,881.000,000,000,000,000
1572 -24,926,804.045,047,420,000,000
1575 SELECT to_char(val, '9999999999999999.999999999999999PR')
1578 ------------------------------------
1581 <34338492.215397047000000>
1583 7799461.411900000000000
1584 16397.038491000000000
1585 93901.577630260000000
1586 <83028485.000000000000000>
1587 74881.000000000000000
1588 <24926804.045047420000000>
1591 SELECT to_char(val, '9999999999999999.999999999999999S')
1594 -----------------------------------
1597 34338492.215397047000000-
1599 7799461.411900000000000+
1600 16397.038491000000000+
1601 93901.577630260000000+
1602 83028485.000000000000000-
1603 74881.000000000000000+
1604 24926804.045047420000000-
1607 SELECT to_char(val, 'MI9999999999999999.999999999999999') FROM num_data;
1609 -----------------------------------
1612 - 34338492.215397047000000
1614 7799461.411900000000000
1615 16397.038491000000000
1616 93901.577630260000000
1617 - 83028485.000000000000000
1618 74881.000000000000000
1619 - 24926804.045047420000000
1622 SELECT to_char(val, 'FMS9999999999999999.999999999999999') FROM num_data;
1624 ---------------------
1637 SELECT to_char(val, 'FM9999999999999999.999999999999999THPR') FROM num_data;
1639 ----------------------
1642 <34338492.215397047>
1652 SELECT to_char(val, 'SG9999999999999999.999999999999999th') FROM num_data;
1654 -----------------------------------
1657 - 34338492.215397047000000
1659 + 7799461.411900000000000
1660 + 16397.038491000000000
1661 + 93901.577630260000000
1662 - 83028485.000000000000000
1663 + 74881.000000000000000
1664 - 24926804.045047420000000
1667 SELECT to_char(val, '0999999999999999.999999999999999') FROM num_data;
1669 -----------------------------------
1670 0000000000000000.000000000000000
1671 0000000000000000.000000000000000
1672 -0000000034338492.215397047000000
1673 0000000000000004.310000000000000
1674 0000000007799461.411900000000000
1675 0000000000016397.038491000000000
1676 0000000000093901.577630260000000
1677 -0000000083028485.000000000000000
1678 0000000000074881.000000000000000
1679 -0000000024926804.045047420000000
1682 SELECT to_char(val, 'S0999999999999999.999999999999999') FROM num_data;
1684 -----------------------------------
1685 +0000000000000000.000000000000000
1686 +0000000000000000.000000000000000
1687 -0000000034338492.215397047000000
1688 +0000000000000004.310000000000000
1689 +0000000007799461.411900000000000
1690 +0000000000016397.038491000000000
1691 +0000000000093901.577630260000000
1692 -0000000083028485.000000000000000
1693 +0000000000074881.000000000000000
1694 -0000000024926804.045047420000000
1697 SELECT to_char(val, 'FM0999999999999999.999999999999999') FROM num_data;
1699 -----------------------------
1702 -0000000034338492.215397047
1704 0000000007799461.4119
1705 0000000000016397.038491
1706 0000000000093901.57763026
1709 -0000000024926804.04504742
1712 SELECT to_char(val, 'FM9999999999999999.099999999999999') FROM num_data;
1714 ---------------------
1727 SELECT to_char(val, 'FM9999999999990999.990999999999999') FROM num_data;
1729 ---------------------
1742 SELECT to_char(val, 'FM0999999999999999.999909999999999') FROM num_data;
1744 -----------------------------
1745 0000000000000000.00000
1746 0000000000000000.00000
1747 -0000000034338492.215397047
1748 0000000000000004.31000
1749 0000000007799461.41190
1750 0000000000016397.038491
1751 0000000000093901.57763026
1752 -0000000083028485.00000
1753 0000000000074881.00000
1754 -0000000024926804.04504742
1757 SELECT to_char(val, 'FM9999999990999999.099999999999999') FROM num_data;
1759 ---------------------
1772 SELECT to_char(val, 'L9999999999999999.099999999999999') FROM num_data;
1774 ------------------------------------
1777 -34338492.215397047000000
1779 7799461.411900000000000
1780 16397.038491000000000
1781 93901.577630260000000
1782 -83028485.000000000000000
1783 74881.000000000000000
1784 -24926804.045047420000000
1787 SELECT to_char(val, 'FM9999999999999999.99999999999999') FROM num_data;
1789 ---------------------
1802 SELECT to_char(val, 'S 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 . 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9') FROM num_data;
1804 -----------------------------------------------------------------------
1805 +. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1806 +. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1807 -3 4 3 3 8 4 9 2 . 2 1 5 3 9 7 0 4 7 0 0 0 0 0 0 0 0
1808 +4 . 3 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1809 +7 7 9 9 4 6 1 . 4 1 1 9 0 0 0 0 0 0 0 0 0 0 0 0 0
1810 +1 6 3 9 7 . 0 3 8 4 9 1 0 0 0 0 0 0 0 0 0 0 0
1811 +9 3 9 0 1 . 5 7 7 6 3 0 2 6 0 0 0 0 0 0 0 0 0
1812 -8 3 0 2 8 4 8 5 . 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1813 +7 4 8 8 1 . 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1814 -2 4 9 2 6 8 0 4 . 0 4 5 0 4 7 4 2 0 0 0 0 0 0 0 0 0
1817 SELECT to_char(val, 'FMS 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 . 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9') FROM num_data;
1819 -------------------------------------------------------
1822 -3 4 3 3 8 4 9 2 . 2 1 5 3 9 7 0 4 7
1824 +7 7 9 9 4 6 1 . 4 1 1 9
1825 +1 6 3 9 7 . 0 3 8 4 9 1
1826 +9 3 9 0 1 . 5 7 7 6 3 0 2 6
1829 -2 4 9 2 6 8 0 4 . 0 4 5 0 4 7 4 2
1832 SELECT to_char(val, E'99999 "text" 9999 "9999" 999 "\\"text between quote marks\\"" 9999') FROM num_data;
1834 -----------------------------------------------------------
1835 text 9999 "text between quote marks" 0
1836 text 9999 "text between quote marks" 0
1837 text -3 9999 433 "text between quote marks" 8492
1838 text 9999 "text between quote marks" 4
1839 text 9999 779 "text between quote marks" 9461
1840 text 9999 1 "text between quote marks" 6397
1841 text 9999 9 "text between quote marks" 3902
1842 text -8 9999 302 "text between quote marks" 8485
1843 text 9999 7 "text between quote marks" 4881
1844 text -2 9999 492 "text between quote marks" 6804
1847 SELECT to_char(val, '999999SG9999999999') FROM num_data;
1862 SELECT to_char(val, 'FM9999999999999999.999999999999999') FROM num_data;
1864 ---------------------
1877 SELECT to_char(val, '9.999EEEE') FROM num_data;
1893 (VALUES('0'::numeric),('-4.2'),('4.2e9'),('1.2e-5'),('inf'),('-inf'),('nan'))
1895 to_char(val, '9.999EEEE') as numeric,
1896 to_char(val::float8, '9.999EEEE') as float8,
1897 to_char(val::float4, '9.999EEEE') as float4
1899 val | numeric | float8 | float4
1900 ------------+------------+------------+------------
1901 0 | 0.000e+00 | 0.000e+00 | 0.000e+00
1902 -4.2 | -4.200e+00 | -4.200e+00 | -4.200e+00
1903 4200000000 | 4.200e+09 | 4.200e+09 | 4.200e+09
1904 0.000012 | 1.200e-05 | 1.200e-05 | 1.200e-05
1905 Infinity | #.####### | #.####### | #.#######
1906 -Infinity | #.####### | #.####### | #.#######
1907 NaN | #.####### | #.####### | #.#######
1911 (VALUES(-16379),(-16378),(-1234),(-789),(-45),(-5),(-4),(-3),(-2),(-1),(0),
1912 (1),(2),(3),(4),(5),(38),(275),(2345),(45678),(131070),(131071))
1914 to_char(('1.2345e'||exp)::numeric, '9.999EEEE') as numeric
1917 --------+----------------
1918 -16379 | 1.235e-16379
1919 -16378 | 1.235e-16378
1937 45678 | 1.235e+45678
1938 131070 | 1.235e+131070
1939 131071 | 1.235e+131071
1943 (VALUES('0'::numeric),('-4.2'),('4.2e9'),('1.2e-5'),('inf'),('-inf'),('nan'))
1945 to_char(val, 'MI9999999999.99') as numeric,
1946 to_char(val::float8, 'MI9999999999.99') as float8,
1947 to_char(val::float4, 'MI9999999999.99') as float4
1949 val | numeric | float8 | float4
1950 ------------+----------------+----------------+----------------
1952 -4.2 | - 4.20 | - 4.20 | - 4.20
1953 4200000000 | 4200000000.00 | 4200000000.00 | 4200000000
1954 0.000012 | .00 | .00 | .00
1955 Infinity | Infinity | Infinity | Infinity
1956 -Infinity | - Infinity | - Infinity | - Infinity
1957 NaN | NaN | NaN | NaN
1961 (VALUES('0'::numeric),('-4.2'),('4.2e9'),('1.2e-5'),('inf'),('-inf'),('nan'))
1963 to_char(val, 'MI99.99') as numeric,
1964 to_char(val::float8, 'MI99.99') as float8,
1965 to_char(val::float4, 'MI99.99') as float4
1967 val | numeric | float8 | float4
1968 ------------+---------+--------+--------
1970 -4.2 | - 4.20 | - 4.20 | - 4.20
1971 4200000000 | ##.## | ##.## | ##.
1972 0.000012 | .00 | .00 | .00
1973 Infinity | ##.## | ##.## | ##.
1974 -Infinity | -##.## | -##.## | -##.
1975 NaN | ##.## | ##.## | ##.##
1978 SELECT to_char('100'::numeric, 'FM999.9');
1984 SELECT to_char('100'::numeric, 'FM999.');
1990 SELECT to_char('100'::numeric, 'FM999');
1996 SELECT to_char('12345678901'::float8, 'FM9999999999D9999900000000000000000');
2002 -- Check parsing of literal text in a format string
2003 SELECT to_char('100'::numeric, 'foo999');
2009 SELECT to_char('100'::numeric, 'f\oo999');
2015 SELECT to_char('100'::numeric, 'f\\oo999');
2021 SELECT to_char('100'::numeric, 'f\"oo999');
2027 SELECT to_char('100'::numeric, 'f\\"oo999');
2033 SELECT to_char('100'::numeric, 'f"ool"999');
2039 SELECT to_char('100'::numeric, 'f"\ool"999');
2045 SELECT to_char('100'::numeric, 'f"\\ool"999');
2051 SELECT to_char('100'::numeric, 'f"ool\"999');
2057 SELECT to_char('100'::numeric, 'f"ool\\"999');
2065 SET lc_numeric = 'C';
2066 SELECT to_number('-34,338,492', '99G999G999');
2072 SELECT to_number('-34,338,492.654,878', '99G999G999D999G999');
2078 SELECT to_number('<564646.654564>', '999999.999999PR');
2084 SELECT to_number('0.00001-', '9.999999S');
2090 SELECT to_number('5.01-', 'FM9.999999S');
2096 SELECT to_number('5.01-', 'FM9.999999MI');
2102 SELECT to_number('5 4 4 4 4 8 . 7 8', '9 9 9 9 9 9 . 9 9');
2108 SELECT to_number('.01', 'FM9.99');
2114 SELECT to_number('.0', '99999999.99999999');
2120 SELECT to_number('0', '99.99');
2126 SELECT to_number('.-01', 'S99.99');
2132 SELECT to_number('.01-', '99.99S');
2138 SELECT to_number(' . 0 1-', ' 9 9 . 9 9 S');
2144 SELECT to_number('34,50','999,99');
2150 SELECT to_number('123,000','999G');
2156 SELECT to_number('123456','999G999');
2162 SELECT to_number('$1234.56','L9,999.99');
2168 SELECT to_number('$1234.56','L99,999.99');
2174 SELECT to_number('$1,234.56','L99,999.99');
2180 SELECT to_number('1234.56','L99,999.99');
2186 SELECT to_number('1,234.56','L99,999.99');
2192 SELECT to_number('42nd', '99th');
2202 CREATE TABLE num_input_test (n1 numeric);
2204 INSERT INTO num_input_test(n1) VALUES (' 123');
2205 INSERT INTO num_input_test(n1) VALUES (' 3245874 ');
2206 INSERT INTO num_input_test(n1) VALUES (' -93853');
2207 INSERT INTO num_input_test(n1) VALUES ('555.50');
2208 INSERT INTO num_input_test(n1) VALUES ('-555.50');
2209 INSERT INTO num_input_test(n1) VALUES ('NaN ');
2210 INSERT INTO num_input_test(n1) VALUES (' nan');
2211 INSERT INTO num_input_test(n1) VALUES (' inf ');
2212 INSERT INTO num_input_test(n1) VALUES (' +inf ');
2213 INSERT INTO num_input_test(n1) VALUES (' -inf ');
2214 INSERT INTO num_input_test(n1) VALUES (' Infinity ');
2215 INSERT INTO num_input_test(n1) VALUES (' +inFinity ');
2216 INSERT INTO num_input_test(n1) VALUES (' -INFINITY ');
2217 INSERT INTO num_input_test(n1) VALUES ('12_000_000_000');
2218 INSERT INTO num_input_test(n1) VALUES ('12_000.123_456');
2219 INSERT INTO num_input_test(n1) VALUES ('23_000_000_000e-1_0');
2220 INSERT INTO num_input_test(n1) VALUES ('.000_000_000_123e1_0');
2221 INSERT INTO num_input_test(n1) VALUES ('.000_000_000_123e+1_1');
2222 INSERT INTO num_input_test(n1) VALUES ('0b10001110111100111100001001010');
2223 INSERT INTO num_input_test(n1) VALUES (' -0B_1010_1011_0101_0100_1010_1001_1000_1100_1110_1011_0001_1111_0000_1010_1101_0010 ');
2224 INSERT INTO num_input_test(n1) VALUES (' +0o112402761777 ');
2225 INSERT INTO num_input_test(n1) VALUES ('-0O0012_5524_5230_6334_3167_0261');
2226 INSERT INTO num_input_test(n1) VALUES ('-0x0000000000000000000000000deadbeef');
2227 INSERT INTO num_input_test(n1) VALUES (' 0X_30b1_F33a_6DF0_bD4E_64DF_9BdA_7D15 ');
2229 INSERT INTO num_input_test(n1) VALUES (' ');
2230 ERROR: invalid input syntax for type numeric: " "
2231 LINE 1: INSERT INTO num_input_test(n1) VALUES (' ');
2233 INSERT INTO num_input_test(n1) VALUES (' 1234 %');
2234 ERROR: invalid input syntax for type numeric: " 1234 %"
2235 LINE 1: INSERT INTO num_input_test(n1) VALUES (' 1234 %');
2237 INSERT INTO num_input_test(n1) VALUES ('xyz');
2238 ERROR: invalid input syntax for type numeric: "xyz"
2239 LINE 1: INSERT INTO num_input_test(n1) VALUES ('xyz');
2241 INSERT INTO num_input_test(n1) VALUES ('- 1234');
2242 ERROR: invalid input syntax for type numeric: "- 1234"
2243 LINE 1: INSERT INTO num_input_test(n1) VALUES ('- 1234');
2245 INSERT INTO num_input_test(n1) VALUES ('5 . 0');
2246 ERROR: invalid input syntax for type numeric: "5 . 0"
2247 LINE 1: INSERT INTO num_input_test(n1) VALUES ('5 . 0');
2249 INSERT INTO num_input_test(n1) VALUES ('5. 0 ');
2250 ERROR: invalid input syntax for type numeric: "5. 0 "
2251 LINE 1: INSERT INTO num_input_test(n1) VALUES ('5. 0 ');
2253 INSERT INTO num_input_test(n1) VALUES ('');
2254 ERROR: invalid input syntax for type numeric: ""
2255 LINE 1: INSERT INTO num_input_test(n1) VALUES ('');
2257 INSERT INTO num_input_test(n1) VALUES (' N aN ');
2258 ERROR: invalid input syntax for type numeric: " N aN "
2259 LINE 1: INSERT INTO num_input_test(n1) VALUES (' N aN ');
2261 INSERT INTO num_input_test(n1) VALUES ('+NaN');
2262 ERROR: invalid input syntax for type numeric: "+NaN"
2263 LINE 1: INSERT INTO num_input_test(n1) VALUES ('+NaN');
2265 INSERT INTO num_input_test(n1) VALUES ('-NaN');
2266 ERROR: invalid input syntax for type numeric: "-NaN"
2267 LINE 1: INSERT INTO num_input_test(n1) VALUES ('-NaN');
2269 INSERT INTO num_input_test(n1) VALUES ('+ infinity');
2270 ERROR: invalid input syntax for type numeric: "+ infinity"
2271 LINE 1: INSERT INTO num_input_test(n1) VALUES ('+ infinity');
2273 INSERT INTO num_input_test(n1) VALUES ('_123');
2274 ERROR: invalid input syntax for type numeric: "_123"
2275 LINE 1: INSERT INTO num_input_test(n1) VALUES ('_123');
2277 INSERT INTO num_input_test(n1) VALUES ('123_');
2278 ERROR: invalid input syntax for type numeric: "123_"
2279 LINE 1: INSERT INTO num_input_test(n1) VALUES ('123_');
2281 INSERT INTO num_input_test(n1) VALUES ('12__34');
2282 ERROR: invalid input syntax for type numeric: "12__34"
2283 LINE 1: INSERT INTO num_input_test(n1) VALUES ('12__34');
2285 INSERT INTO num_input_test(n1) VALUES ('123_.456');
2286 ERROR: invalid input syntax for type numeric: "123_.456"
2287 LINE 1: INSERT INTO num_input_test(n1) VALUES ('123_.456');
2289 INSERT INTO num_input_test(n1) VALUES ('123._456');
2290 ERROR: invalid input syntax for type numeric: "123._456"
2291 LINE 1: INSERT INTO num_input_test(n1) VALUES ('123._456');
2293 INSERT INTO num_input_test(n1) VALUES ('1.2e_34');
2294 ERROR: invalid input syntax for type numeric: "1.2e_34"
2295 LINE 1: INSERT INTO num_input_test(n1) VALUES ('1.2e_34');
2297 INSERT INTO num_input_test(n1) VALUES ('1.2e34_');
2298 ERROR: invalid input syntax for type numeric: "1.2e34_"
2299 LINE 1: INSERT INTO num_input_test(n1) VALUES ('1.2e34_');
2301 INSERT INTO num_input_test(n1) VALUES ('1.2e3__4');
2302 ERROR: invalid input syntax for type numeric: "1.2e3__4"
2303 LINE 1: INSERT INTO num_input_test(n1) VALUES ('1.2e3__4');
2305 INSERT INTO num_input_test(n1) VALUES ('0b1112');
2306 ERROR: invalid input syntax for type numeric: "0b1112"
2307 LINE 1: INSERT INTO num_input_test(n1) VALUES ('0b1112');
2309 INSERT INTO num_input_test(n1) VALUES ('0c1112');
2310 ERROR: invalid input syntax for type numeric: "0c1112"
2311 LINE 1: INSERT INTO num_input_test(n1) VALUES ('0c1112');
2313 INSERT INTO num_input_test(n1) VALUES ('0o12345678');
2314 ERROR: invalid input syntax for type numeric: "0o12345678"
2315 LINE 1: INSERT INTO num_input_test(n1) VALUES ('0o12345678');
2317 INSERT INTO num_input_test(n1) VALUES ('0x1eg');
2318 ERROR: invalid input syntax for type numeric: "0x1eg"
2319 LINE 1: INSERT INTO num_input_test(n1) VALUES ('0x1eg');
2321 INSERT INTO num_input_test(n1) VALUES ('0x12.34');
2322 ERROR: invalid input syntax for type numeric: "0x12.34"
2323 LINE 1: INSERT INTO num_input_test(n1) VALUES ('0x12.34');
2325 INSERT INTO num_input_test(n1) VALUES ('0x__1234');
2326 ERROR: invalid input syntax for type numeric: "0x__1234"
2327 LINE 1: INSERT INTO num_input_test(n1) VALUES ('0x__1234');
2329 INSERT INTO num_input_test(n1) VALUES ('0x1234_');
2330 ERROR: invalid input syntax for type numeric: "0x1234_"
2331 LINE 1: INSERT INTO num_input_test(n1) VALUES ('0x1234_');
2333 INSERT INTO num_input_test(n1) VALUES ('0x12__34');
2334 ERROR: invalid input syntax for type numeric: "0x12__34"
2335 LINE 1: INSERT INTO num_input_test(n1) VALUES ('0x12__34');
2337 SELECT * FROM num_input_test;
2339 -----------------------------------
2359 -12345678901234567890
2361 -12345678900987654321
2363 987654321234567898765432123456789
2366 -- Also try it with non-error-throwing API
2367 SELECT pg_input_is_valid('34.5', 'numeric');
2373 SELECT pg_input_is_valid('34xyz', 'numeric');
2379 SELECT pg_input_is_valid('1e400000', 'numeric');
2385 SELECT * FROM pg_input_error_info('1e400000', 'numeric');
2386 message | detail | hint | sql_error_code
2387 --------------------------------+--------+------+----------------
2388 value overflows numeric format | | | 22003
2391 SELECT pg_input_is_valid('1234.567', 'numeric(8,4)');
2397 SELECT pg_input_is_valid('1234.567', 'numeric(7,4)');
2403 SELECT * FROM pg_input_error_info('1234.567', 'numeric(7,4)');
2404 message | detail | hint | sql_error_code
2405 ------------------------+-----------------------------------------------------------------------------------+------+----------------
2406 numeric field overflow | A field with precision 7, scale 4 must round to an absolute value less than 10^3. | | 22003
2409 SELECT * FROM pg_input_error_info('0x1234.567', 'numeric');
2410 message | detail | hint | sql_error_code
2411 -----------------------------------------------------+--------+------+----------------
2412 invalid input syntax for type numeric: "0x1234.567" | | | 22P02
2416 -- Test precision and scale typemods
2418 CREATE TABLE num_typemod_test (
2419 millions numeric(3, -6),
2420 thousands numeric(3, -3),
2421 units numeric(3, 0),
2422 thousandths numeric(3, 3),
2423 millionths numeric(3, 6)
2426 Table "public.num_typemod_test"
2427 Column | Type | Collation | Nullable | Default
2428 -------------+---------------+-----------+----------+---------
2429 millions | numeric(3,-6) | | |
2430 thousands | numeric(3,-3) | | |
2431 units | numeric(3,0) | | |
2432 thousandths | numeric(3,3) | | |
2433 millionths | numeric(3,6) | | |
2435 -- rounding of valid inputs
2436 INSERT INTO num_typemod_test VALUES (123456, 123, 0.123, 0.000123, 0.000000123);
2437 INSERT INTO num_typemod_test VALUES (654321, 654, 0.654, 0.000654, 0.000000654);
2438 INSERT INTO num_typemod_test VALUES (2345678, 2345, 2.345, 0.002345, 0.000002345);
2439 INSERT INTO num_typemod_test VALUES (7654321, 7654, 7.654, 0.007654, 0.000007654);
2440 INSERT INTO num_typemod_test VALUES (12345678, 12345, 12.345, 0.012345, 0.000012345);
2441 INSERT INTO num_typemod_test VALUES (87654321, 87654, 87.654, 0.087654, 0.000087654);
2442 INSERT INTO num_typemod_test VALUES (123456789, 123456, 123.456, 0.123456, 0.000123456);
2443 INSERT INTO num_typemod_test VALUES (987654321, 987654, 987.654, 0.987654, 0.000987654);
2444 INSERT INTO num_typemod_test VALUES ('NaN', 'NaN', 'NaN', 'NaN', 'NaN');
2445 SELECT scale(millions), * FROM num_typemod_test ORDER BY millions;
2446 scale | millions | thousands | units | thousandths | millionths
2447 -------+-----------+-----------+-------+-------------+------------
2448 0 | 0 | 0 | 0 | 0.000 | 0.000000
2449 0 | 1000000 | 1000 | 1 | 0.001 | 0.000001
2450 0 | 2000000 | 2000 | 2 | 0.002 | 0.000002
2451 0 | 8000000 | 8000 | 8 | 0.008 | 0.000008
2452 0 | 12000000 | 12000 | 12 | 0.012 | 0.000012
2453 0 | 88000000 | 88000 | 88 | 0.088 | 0.000088
2454 0 | 123000000 | 123000 | 123 | 0.123 | 0.000123
2455 0 | 988000000 | 988000 | 988 | 0.988 | 0.000988
2456 | NaN | NaN | NaN | NaN | NaN
2460 INSERT INTO num_typemod_test (millions) VALUES ('inf');
2461 ERROR: numeric field overflow
2462 DETAIL: A field with precision 3, scale -6 cannot hold an infinite value.
2463 INSERT INTO num_typemod_test (millions) VALUES (999500000);
2464 ERROR: numeric field overflow
2465 DETAIL: A field with precision 3, scale -6 must round to an absolute value less than 10^9.
2466 INSERT INTO num_typemod_test (thousands) VALUES (999500);
2467 ERROR: numeric field overflow
2468 DETAIL: A field with precision 3, scale -3 must round to an absolute value less than 10^6.
2469 INSERT INTO num_typemod_test (units) VALUES (999.5);
2470 ERROR: numeric field overflow
2471 DETAIL: A field with precision 3, scale 0 must round to an absolute value less than 10^3.
2472 INSERT INTO num_typemod_test (thousandths) VALUES (0.9995);
2473 ERROR: numeric field overflow
2474 DETAIL: A field with precision 3, scale 3 must round to an absolute value less than 1.
2475 INSERT INTO num_typemod_test (millionths) VALUES (0.0009995);
2476 ERROR: numeric field overflow
2477 DETAIL: A field with precision 3, scale 6 must round to an absolute value less than 10^-3.
2479 -- Test some corner cases for multiplication
2481 select 4790999999999999999999999999999999999999999999999999999999999999999999999999999999999999 * 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999;
2483 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2484 47909999999999999999999999999999999999999999999999999999999999999999999999999999999999985209000000000000000000000000000000000000000000000000000000000000000000000000000000000001
2487 select 4789999999999999999999999999999999999999999999999999999999999999999999999999999999999999 * 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999;
2489 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2490 47899999999999999999999999999999999999999999999999999999999999999999999999999999999999985210000000000000000000000000000000000000000000000000000000000000000000000000000000000001
2493 select 4770999999999999999999999999999999999999999999999999999999999999999999999999999999999999 * 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999;
2495 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2496 47709999999999999999999999999999999999999999999999999999999999999999999999999999999999985229000000000000000000000000000000000000000000000000000000000000000000000000000000000001
2499 select 4769999999999999999999999999999999999999999999999999999999999999999999999999999999999999 * 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999;
2501 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2502 47699999999999999999999999999999999999999999999999999999999999999999999999999999999999985230000000000000000000000000000000000000000000000000000000000000000000000000000000000001
2505 select trim_scale((0.1 - 2e-16383) * (0.1 - 3e-16383));
2512 -- Test some corner cases for division
2514 select 999999999999999999999::numeric/1000000000000000000000;
2516 ------------------------
2517 1.00000000000000000000
2520 select div(999999999999999999999::numeric,1000000000000000000000);
2526 select mod(999999999999999999999::numeric,1000000000000000000000);
2528 -----------------------
2529 999999999999999999999
2532 select div(-9999999999999999999999::numeric,1000000000000000000000);
2538 select mod(-9999999999999999999999::numeric,1000000000000000000000);
2540 ------------------------
2541 -999999999999999999999
2544 select div(-9999999999999999999999::numeric,1000000000000000000000)*1000000000000000000000 + mod(-9999999999999999999999::numeric,1000000000000000000000);
2546 -------------------------
2547 -9999999999999999999999
2550 select mod (70.0,70) ;
2556 select div (70.0,70) ;
2564 ------------------------
2565 1.00000000000000000000
2568 select 12345678901234567890 % 123;
2574 select 12345678901234567890 / 123;
2576 --------------------
2580 select div(12345678901234567890, 123);
2582 --------------------
2586 select div(12345678901234567890, 123) * 123 + 12345678901234567890 % 123;
2588 ----------------------
2589 12345678901234567890
2593 -- Test some corner cases for square root
2595 select sqrt(1.000000000000003::numeric);
2601 select sqrt(1.000000000000004::numeric);
2607 select sqrt(96627521408608.56340355805::numeric);
2609 ---------------------
2613 select sqrt(96627521408608.56340355806::numeric);
2615 ---------------------
2619 select sqrt(515549506212297735.073688290367::numeric);
2621 ------------------------
2622 718017761.766585921184
2625 select sqrt(515549506212297735.073688290368::numeric);
2627 ------------------------
2628 718017761.766585921185
2631 select sqrt(8015491789940783531003294973900306::numeric);
2637 select sqrt(8015491789940783531003294973900307::numeric);
2644 -- Test code path for raising to integer powers
2646 select 10.0 ^ -2147483648 as rounds_to_zero;
2648 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2649 0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
2652 select 10.0 ^ -2147483647 as rounds_to_zero;
2654 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2655 0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
2658 select 10.0 ^ 2147483647 as overflows;
2659 ERROR: value overflows numeric format
2660 select 117743296169.0 ^ 1000000000 as overflows;
2661 ERROR: value overflows numeric format
2662 -- cases that used to return inaccurate results
2663 select 3.789 ^ 21.0000000000000000;
2665 --------------------------------
2666 1409343026052.8716016316022141
2669 select 3.789 ^ 35.0000000000000000;
2671 ----------------------------------------
2672 177158169650516670809.3820586142670135
2677 --------------------------------
2678 2077446682327378559843444695.6
2681 select 0.12 ^ (-20);
2683 ------------------------
2684 2608405330458882702.55
2687 select 1.000000000123 ^ (-2147483648);
2689 --------------------
2693 select coalesce(nullif(0.9999999999 ^ 23300000000000, 0), 0) as rounds_to_zero;
2699 select round(((1 - 1.500012345678e-1000) ^ 1.45e1003) * 1e1000);
2701 ----------------------------------------------------------
2702 25218976308958387188077465658068501556514992509509282366
2705 -- cases that used to error out
2706 select 0.12 ^ (-25);
2708 -----------------------------
2709 104825960103961013959336.50
2712 select 0.5678 ^ (-85);
2714 ----------------------------
2715 782333637740774446257.7719
2718 select coalesce(nullif(0.9999999999 ^ 70000000000000, 0), 0) as underflows;
2724 -- negative base to integer powers
2725 select (-1.0) ^ 2147483646;
2727 --------------------
2731 select (-1.0) ^ 2147483647;
2733 ---------------------
2737 select (-1.0) ^ 2147483648;
2739 --------------------
2743 select (-1.0) ^ 1000000000000000;
2745 --------------------
2749 select (-1.0) ^ 1000000000000001;
2751 ---------------------
2755 -- integer powers of 10
2756 select n, 10.0 ^ n as "10^n", (10.0 ^ n) * (10.0 ^ (-n)) = 1 as ok
2757 from generate_series(-20, 20) n;
2759 -----+----------------------------------------+----
2760 -20 | 0.000000000000000000010000000000000000 | t
2761 -19 | 0.00000000000000000010000000000000000 | t
2762 -18 | 0.0000000000000000010000000000000000 | t
2763 -17 | 0.000000000000000010000000000000000 | t
2764 -16 | 0.00000000000000010000000000000000 | t
2765 -15 | 0.0000000000000010000000000000000 | t
2766 -14 | 0.000000000000010000000000000000 | t
2767 -13 | 0.00000000000010000000000000000 | t
2768 -12 | 0.0000000000010000000000000000 | t
2769 -11 | 0.000000000010000000000000000 | t
2770 -10 | 0.00000000010000000000000000 | t
2771 -9 | 0.0000000010000000000000000 | t
2772 -8 | 0.000000010000000000000000 | t
2773 -7 | 0.00000010000000000000000 | t
2774 -6 | 0.0000010000000000000000 | t
2775 -5 | 0.000010000000000000000 | t
2776 -4 | 0.00010000000000000000 | t
2777 -3 | 0.0010000000000000000 | t
2778 -2 | 0.010000000000000000 | t
2779 -1 | 0.10000000000000000 | t
2780 0 | 1.0000000000000000 | t
2781 1 | 10.000000000000000 | t
2782 2 | 100.00000000000000 | t
2783 3 | 1000.0000000000000 | t
2784 4 | 10000.000000000000 | t
2785 5 | 100000.00000000000 | t
2786 6 | 1000000.0000000000 | t
2787 7 | 10000000.000000000 | t
2788 8 | 100000000.00000000 | t
2789 9 | 1000000000.0000000 | t
2790 10 | 10000000000.000000 | t
2791 11 | 100000000000.00000 | t
2792 12 | 1000000000000.0000 | t
2793 13 | 10000000000000.000 | t
2794 14 | 100000000000000.00 | t
2795 15 | 1000000000000000.0 | t
2796 16 | 10000000000000000.0 | t
2797 17 | 100000000000000000.0 | t
2798 18 | 1000000000000000000.0 | t
2799 19 | 10000000000000000000.0 | t
2800 20 | 100000000000000000000.0 | t
2804 -- Tests for raising to non-integer powers
2809 --------------------
2813 select (-12.34) ^ 0.0;
2815 --------------------
2821 --------------------
2827 --------------------
2832 select 'NaN'::numeric ^ 'NaN'::numeric;
2838 select 'NaN'::numeric ^ 0;
2844 select 'NaN'::numeric ^ 1;
2850 select 0 ^ 'NaN'::numeric;
2856 select 1 ^ 'NaN'::numeric;
2863 select 0.0 ^ (-12.34);
2864 ERROR: zero raised to a negative power is undefined
2865 select (-12.34) ^ 1.2;
2866 ERROR: a negative number raised to a non-integer power yields a complex result
2867 -- cases that used to generate inaccurate results
2870 --------------------
2874 select 32.1 ^ (-9.8);
2876 ----------------------------------
2877 0.000000000000001722862754788209
2882 ------------------------------------------------------
2883 50081010321492803393171165777624533697036806969694.9
2886 select 12.3 ^ (-45.6);
2888 ---------------------------------------------------------------------
2889 0.00000000000000000000000000000000000000000000000001996764828785491
2893 select 1.234 ^ 5678;
2895 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2896 307239295662090741644584872593956173493568238595074141254349565406661439636598896798876823220904084953233015553994854875890890858118656468658643918169805277399402542281777901029346337707622181574346585989613344285010764501017625366742865066948856161360224801370482171458030533346309750557140549621313515752078638620714732831815297168231790779296290266207315344008883935010274044001522606235576584215999260117523114297033944018699691024106823438431754073086813382242140602291215149759520833200152654884259619588924545324.597
2905 --------------------
2911 --------------------
2915 select exp(1.0::numeric(71,70));
2917 --------------------------------------------------------------------------
2918 2.7182818284590452353602874713526624977572470936999595749669676277240766
2921 select exp('nan'::numeric);
2927 select exp('inf'::numeric);
2933 select exp('-inf'::numeric);
2939 select coalesce(nullif(exp(-5000::numeric), 0), 0) as rounds_to_zero;
2945 select coalesce(nullif(exp(-10000::numeric), 0), 0) as underflows;
2951 -- cases that used to generate inaccurate results
2954 ---------------------
2958 select exp(-32.999);
2960 ----------------------------------
2961 0.000000000000004663547361468248
2964 select exp(123.456);
2966 ------------------------------------------------------------
2967 413294435277809344957685441227343146614594393746575438.725
2970 select exp(-123.456);
2972 -------------------------------------------------------------------------
2973 0.000000000000000000000000000000000000000000000000000002419582541264601
2977 select exp(1234.5678);
2979 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2980 146549072930959479983482138503979804217622199675223653966270157446954995433819741094410764947112047906012815540251009949604426069672532417736057033099274204598385314594846509975629046864798765888104789074984927709616261452461385220475510438783429612447831614003668421849727379202555580791042606170523016207262965336641214601082882495255771621327088265411334088968112458492660609809762865582162764292604697957813514621259353683899630997077707406305730694385703091201347848855199354307506425820147289848677003277208302716466011827836279231.9667
2984 -- Tests for generate_series
2986 select * from generate_series(0.0::numeric, 4.0::numeric);
2996 select * from generate_series(0.1::numeric, 4.0::numeric, 1.3::numeric);
3005 select * from generate_series(4.0::numeric, -1.5::numeric, -2.2::numeric);
3014 select * from generate_series(-100::numeric, 100::numeric, 0::numeric);
3015 ERROR: step size cannot equal zero
3016 select * from generate_series(-100::numeric, 100::numeric, 'nan'::numeric);
3017 ERROR: step size cannot be NaN
3018 select * from generate_series('nan'::numeric, 100::numeric, 10::numeric);
3019 ERROR: start value cannot be NaN
3020 select * from generate_series(0::numeric, 'nan'::numeric, 10::numeric);
3021 ERROR: stop value cannot be NaN
3022 select * from generate_series('inf'::numeric, 'inf'::numeric, 10::numeric);
3023 ERROR: start value cannot be infinity
3024 select * from generate_series(0::numeric, 'inf'::numeric, 10::numeric);
3025 ERROR: stop value cannot be infinity
3026 select * from generate_series(0::numeric, '42'::numeric, '-inf'::numeric);
3027 ERROR: step size cannot be infinity
3028 -- Checks maximum, output is truncated
3029 select (i / (10::numeric ^ 131071))::numeric(1,0)
3030 from generate_series(6 * (10::numeric ^ 131071),
3031 9 * (10::numeric ^ 131071),
3032 10::numeric ^ 131071) as a(i);
3041 -- Check usage with variables
3042 select * from generate_series(1::numeric, 3::numeric) i, generate_series(i,3) j;
3053 select * from generate_series(1::numeric, 3::numeric) i, generate_series(1,i) j;
3064 select * from generate_series(1::numeric, 3::numeric) i, generate_series(1,5,i) j;
3084 ERROR: cannot take logarithm of a negative number
3086 ERROR: cannot take logarithm of zero
3087 -- Some random tests
3088 select ln(1.2345678e-28);
3090 -----------------------------------------
3091 -64.26166165451762991204894255882820859
3094 select ln(0.0456789);
3096 ---------------------
3100 select ln(0.349873948359354029493948309745709580730482050975);
3102 -----------------------------------------------------
3103 -1.050182336912082775693991697979750253056317885460
3106 select ln(0.99949452);
3108 -------------------------
3109 -0.00050560779808326467
3112 select ln(1.00049687395);
3114 ------------------------
3115 0.00049675054901370394
3118 select ln(1234.567890123456789);
3120 --------------------
3124 select ln(5.80397490724e5);
3126 --------------------
3130 select ln(9.342536355e34);
3132 --------------------
3137 -- Tests for LOG() (base 10)
3141 ERROR: cannot take logarithm of a negative number
3142 CONTEXT: SQL function "log" statement 1
3144 ERROR: cannot take logarithm of zero
3145 CONTEXT: SQL function "log" statement 1
3146 -- some random tests
3147 select log(1.234567e-89);
3149 -----------------------------------------------------------------------------------------------------
3150 -88.90848533591373725637496492944925187293052336306443143312825869985819779294142441287021741054275
3153 select log(3.4634998359873254962349856073435545);
3155 --------------------------------------
3156 0.5395151714070134409152404011959981
3159 select log(9.999999999999999999);
3161 ----------------------
3162 1.000000000000000000
3165 select log(10.00000000000000000);
3167 ---------------------
3171 select log(10.00000000000000001);
3173 ---------------------
3177 select log(590489.45235237);
3184 -- Tests for LOG() (arbitrary base)
3187 select log(-12.34, 56.78);
3188 ERROR: cannot take logarithm of a negative number
3189 select log(-12.34, -56.78);
3190 ERROR: cannot take logarithm of a negative number
3191 select log(12.34, -56.78);
3192 ERROR: cannot take logarithm of a negative number
3193 select log(0.0, 12.34);
3194 ERROR: cannot take logarithm of zero
3195 select log(12.34, 0.0);
3196 ERROR: cannot take logarithm of zero
3197 select log(1.0, 12.34);
3198 ERROR: division by zero
3199 -- some random tests
3200 select log(1.23e-89, 6.4689e45);
3202 ------------------------------------------------------------------------------------------------
3203 -0.5152489207781856983977054971756484879653568168479201885425588841094788842469115325262329756
3206 select log(0.99923, 4.58934e34);
3208 ---------------------
3212 select log(1.000016, 8.452010e18);
3214 --------------------
3218 select log(3.1954752e47, 9.4792021e-73);
3220 -------------------------------------------------------------------------------------
3221 -1.51613372350688302142917386143459361608600157692779164475351842333265418126982165
3225 -- Tests for scale()
3227 select scale(numeric 'NaN');
3233 select scale(numeric 'inf');
3239 select scale(NULL::numeric);
3263 select scale(1.12345);
3269 select scale(110123.12475871856128);
3275 select scale(-1123.12471856128);
3281 select scale(-13.000000000000000);
3288 -- Tests for min_scale()
3290 select min_scale(numeric 'NaN') is NULL; -- should be true
3296 select min_scale(numeric 'inf') is NULL; -- should be true
3302 select min_scale(0); -- no digits
3308 select min_scale(0.00); -- no digits again
3314 select min_scale(1.0); -- no scale
3320 select min_scale(1.1); -- scale 1
3326 select min_scale(1.12); -- scale 2
3332 select min_scale(1.123); -- scale 3
3338 select min_scale(1.1234); -- scale 4, filled digit
3344 select min_scale(1.12345); -- scale 5, 2 NDIGITS
3350 select min_scale(1.1000); -- 1 pos in NDIGITS
3356 select min_scale(1e100); -- very big number
3363 -- Tests for trim_scale()
3365 select trim_scale(numeric 'NaN');
3371 select trim_scale(numeric 'inf');
3377 select trim_scale(1.120);
3383 select trim_scale(0);
3389 select trim_scale(0.00);
3395 select trim_scale(1.1234500);
3401 select trim_scale(110123.12475871856128000);
3403 -----------------------
3404 110123.12475871856128
3407 select trim_scale(-1123.124718561280000000);
3413 select trim_scale(-13.00000000000000000000);
3419 select trim_scale(1e100);
3421 -------------------------------------------------------------------------------------------------------
3422 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
3428 -- cases that need carry propagation
3429 SELECT SUM(9999::numeric) FROM generate_series(1, 100000);
3435 SELECT SUM((-9999)::numeric) FROM generate_series(1, 100000);
3442 -- Tests for VARIANCE()
3444 CREATE TABLE num_variance (a numeric);
3445 INSERT INTO num_variance VALUES (0);
3446 INSERT INTO num_variance VALUES (3e-500);
3447 INSERT INTO num_variance VALUES (-3e-500);
3448 INSERT INTO num_variance VALUES (4e-500 - 1e-16383);
3449 INSERT INTO num_variance VALUES (-4e-500 + 1e-16383);
3450 -- variance is just under 12.5e-1000 and so should round down to 12e-1000
3451 SELECT trim_scale(variance(a) * 1e1000) FROM num_variance;
3457 -- check that parallel execution produces the same result
3459 ALTER TABLE num_variance SET (parallel_workers = 4);
3460 SET LOCAL parallel_setup_cost = 0;
3461 SET LOCAL max_parallel_workers_per_gather = 4;
3462 SELECT trim_scale(variance(a) * 1e1000) FROM num_variance;
3469 -- case where sum of squares would overflow but variance does not
3470 DELETE FROM num_variance;
3471 INSERT INTO num_variance SELECT 9e131071 + x FROM generate_series(1, 5) x;
3472 SELECT variance(a) FROM num_variance;
3474 --------------------
3478 -- check that parallel execution produces the same result
3480 ALTER TABLE num_variance SET (parallel_workers = 4);
3481 SET LOCAL parallel_setup_cost = 0;
3482 SET LOCAL max_parallel_workers_per_gather = 4;
3483 SELECT variance(a) FROM num_variance;
3485 --------------------
3490 DROP TABLE num_variance;
3494 SELECT a, b, gcd(a, b), gcd(a, -b), gcd(-b, a), gcd(-b, -a)
3495 FROM (VALUES (0::numeric, 0::numeric),
3496 (0::numeric, numeric 'NaN'),
3497 (0::numeric, 46375::numeric),
3498 (433125::numeric, 46375::numeric),
3499 (43312.5::numeric, 4637.5::numeric),
3500 (4331.250::numeric, 463.75000::numeric),
3505 a | b | gcd | gcd | gcd | gcd
3506 ----------+-----------+---------+---------+---------+---------
3507 0 | 0 | 0 | 0 | 0 | 0
3508 0 | NaN | NaN | NaN | NaN | NaN
3509 0 | 46375 | 46375 | 46375 | 46375 | 46375
3510 433125 | 46375 | 875 | 875 | 875 | 875
3511 43312.5 | 4637.5 | 87.5 | 87.5 | 87.5 | 87.5
3512 4331.250 | 463.75000 | 8.75000 | 8.75000 | 8.75000 | 8.75000
3513 Infinity | 0 | NaN | NaN | NaN | NaN
3514 Infinity | 42 | NaN | NaN | NaN | NaN
3515 Infinity | Infinity | NaN | NaN | NaN | NaN
3521 SELECT a,b, lcm(a, b), lcm(a, -b), lcm(-b, a), lcm(-b, -a)
3522 FROM (VALUES (0::numeric, 0::numeric),
3523 (0::numeric, numeric 'NaN'),
3524 (0::numeric, 13272::numeric),
3525 (13272::numeric, 13272::numeric),
3526 (423282::numeric, 13272::numeric),
3527 (42328.2::numeric, 1327.2::numeric),
3528 (4232.820::numeric, 132.72000::numeric),
3533 a | b | lcm | lcm | lcm | lcm
3534 ----------+-----------+--------------+--------------+--------------+--------------
3535 0 | 0 | 0 | 0 | 0 | 0
3536 0 | NaN | NaN | NaN | NaN | NaN
3537 0 | 13272 | 0 | 0 | 0 | 0
3538 13272 | 13272 | 13272 | 13272 | 13272 | 13272
3539 423282 | 13272 | 11851896 | 11851896 | 11851896 | 11851896
3540 42328.2 | 1327.2 | 1185189.6 | 1185189.6 | 1185189.6 | 1185189.6
3541 4232.820 | 132.72000 | 118518.96000 | 118518.96000 | 118518.96000 | 118518.96000
3542 Infinity | 0 | NaN | NaN | NaN | NaN
3543 Infinity | 42 | NaN | NaN | NaN | NaN
3544 Infinity | Infinity | NaN | NaN | NaN | NaN
3547 SELECT lcm(9999 * (10::numeric)^131068 + (10::numeric^131068 - 1), 2); -- overflow
3548 ERROR: value overflows numeric format
3550 -- Tests for factorial
3552 SELECT factorial(4);
3558 SELECT factorial(15);
3564 SELECT factorial(100000);
3565 ERROR: value overflows numeric format
3566 SELECT factorial(0);
3572 SELECT factorial(-4);
3573 ERROR: factorial of a negative number is undefined
3575 -- Tests for pg_lsn()
3577 SELECT pg_lsn(23783416::numeric);
3583 SELECT pg_lsn(0::numeric);
3589 SELECT pg_lsn(18446744073709551615::numeric);
3595 SELECT pg_lsn(-1::numeric);
3596 ERROR: pg_lsn out of range
3597 SELECT pg_lsn(18446744073709551616::numeric);
3598 ERROR: pg_lsn out of range
3599 SELECT pg_lsn('NaN'::numeric);
3600 ERROR: cannot convert NaN to pg_lsn