Make float exponent output on Windows look the same as elsewhere.

Windows, alone among our supported platforms, likes to emit three-digit
exponent fields even when two digits would do.  Adjust such results to
look like the way everyone else does it.  Eliminate a bunch of variant
expected-output files that were needed only because of this quirk.

Discussion: https://postgr.es/m/2934.1539122454@sss.pgh.pa.us
This commit is contained in:
Tom Lane 2018-10-12 11:14:27 -04:00
parent b34e84f160
commit f1885386f6
12 changed files with 27 additions and 10435 deletions

View File

@ -1,106 +0,0 @@
---
--- Testing cube output in scientific notation. This was put into separate
--- test, because has platform-depending output.
---
SELECT '1e27'::cube AS cube;
cube
----------
(1e+027)
(1 row)
SELECT '-1e27'::cube AS cube;
cube
-----------
(-1e+027)
(1 row)
SELECT '1.0e27'::cube AS cube;
cube
----------
(1e+027)
(1 row)
SELECT '-1.0e27'::cube AS cube;
cube
-----------
(-1e+027)
(1 row)
SELECT '1e+27'::cube AS cube;
cube
----------
(1e+027)
(1 row)
SELECT '-1e+27'::cube AS cube;
cube
-----------
(-1e+027)
(1 row)
SELECT '1.0e+27'::cube AS cube;
cube
----------
(1e+027)
(1 row)
SELECT '-1.0e+27'::cube AS cube;
cube
-----------
(-1e+027)
(1 row)
SELECT '1e-7'::cube AS cube;
cube
----------
(1e-007)
(1 row)
SELECT '-1e-7'::cube AS cube;
cube
-----------
(-1e-007)
(1 row)
SELECT '1.0e-7'::cube AS cube;
cube
----------
(1e-007)
(1 row)
SELECT '-1.0e-7'::cube AS cube;
cube
-----------
(-1e-007)
(1 row)
SELECT '1e-300'::cube AS cube;
cube
----------
(1e-300)
(1 row)
SELECT '-1e-300'::cube AS cube;
cube
-----------
(-1e-300)
(1 row)
SELECT '1234567890123456'::cube AS cube;
cube
-------------------------
(1.23456789012346e+015)
(1 row)
SELECT '+1234567890123456'::cube AS cube;
cube
-------------------------
(1.23456789012346e+015)
(1 row)
SELECT '-1234567890123456'::cube AS cube;
cube
--------------------------
(-1.23456789012346e+015)
(1 row)

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +0,0 @@
from int = 1407.0
add = 2379.7
sub = 2369.7
mul = 13306998429.873000000
div = 1330699.84298730000 1.330700e+006
to long(0) = 20000000 14

View File

@ -1,12 +0,0 @@
compat_informix/dec_test:stdout:i.86-pc-win32vc=compat_informix-dec_test-MinGW32.stdout
compat_informix/dec_test:stdout:i.86-pc-mingw32=compat_informix-dec_test-MinGW32.stdout
compat_informix/dec_test:stdout:x86_64-w64-mingw32=compat_informix-dec_test-MinGW32.stdout
compat_informix/dec_test:stdout:i.86-w64-mingw32=compat_informix-dec_test-MinGW32.stdout
pgtypeslib/num_test:stdout:i.86-pc-win32vc=pgtypeslib-num_test-MinGW32.stdout
pgtypeslib/num_test:stdout:i.86-pc-mingw32=pgtypeslib-num_test-MinGW32.stdout
pgtypeslib/num_test:stdout:x86_64-w64-mingw32=pgtypeslib-num_test-MinGW32.stdout
pgtypeslib/num_test:stdout:i.86-w64-mingw32=pgtypeslib-num_test-MinGW32.stdout
pgtypeslib/num_test2:stdout:i.86-pc-win32vc=pgtypeslib-num_test2-MinGW32.stdout
pgtypeslib/num_test2:stdout:i.86-pc-mingw32=pgtypeslib-num_test2-MinGW32.stdout
pgtypeslib/num_test2:stdout:x86_64-w64-mingw32=pgtypeslib-num_test2-MinGW32.stdout
pgtypeslib/num_test2:stdout:i.86-w64-mingw32=pgtypeslib-num_test2-MinGW32.stdout

View File

@ -1181,6 +1181,22 @@ fmtfloat(double value, char type, int forcesign, int leftjust,
}
if (vallen < 0)
goto fail;
/*
* Windows, alone among our supported platforms, likes to emit
* three-digit exponent fields even when two digits would do. Hack
* such results to look like the way everyone else does it.
*/
#ifdef WIN32
if (vallen >= 6 &&
convert[vallen - 5] == 'e' &&
convert[vallen - 3] == '0')
{
convert[vallen - 3] = convert[vallen - 2];
convert[vallen - 2] = convert[vallen - 1];
vallen--;
}
#endif
}
padlen = compute_padlen(minlen, vallen + zeropadlen, leftjust);
@ -1298,6 +1314,17 @@ pg_strfromd(char *str, size_t count, int precision, double value)
target.failed = true;
goto fail;
}
#ifdef WIN32
if (vallen >= 6 &&
convert[vallen - 5] == 'e' &&
convert[vallen - 3] == '0')
{
convert[vallen - 3] = convert[vallen - 2];
convert[vallen - 2] = convert[vallen - 1];
vallen--;
}
#endif
}
}

View File

@ -1,259 +0,0 @@
--
-- FLOAT4
--
CREATE TABLE FLOAT4_TBL (f1 float4);
INSERT INTO FLOAT4_TBL(f1) VALUES (' 0.0');
INSERT INTO FLOAT4_TBL(f1) VALUES ('1004.30 ');
INSERT INTO FLOAT4_TBL(f1) VALUES (' -34.84 ');
INSERT INTO FLOAT4_TBL(f1) VALUES ('1.2345678901234e+20');
INSERT INTO FLOAT4_TBL(f1) VALUES ('1.2345678901234e-20');
-- test for over and under flow
INSERT INTO FLOAT4_TBL(f1) VALUES ('10e70');
ERROR: value out of range: overflow
LINE 1: INSERT INTO FLOAT4_TBL(f1) VALUES ('10e70');
^
INSERT INTO FLOAT4_TBL(f1) VALUES ('-10e70');
ERROR: value out of range: overflow
LINE 1: INSERT INTO FLOAT4_TBL(f1) VALUES ('-10e70');
^
INSERT INTO FLOAT4_TBL(f1) VALUES ('10e-70');
ERROR: value out of range: underflow
LINE 1: INSERT INTO FLOAT4_TBL(f1) VALUES ('10e-70');
^
INSERT INTO FLOAT4_TBL(f1) VALUES ('-10e-70');
ERROR: value out of range: underflow
LINE 1: INSERT INTO FLOAT4_TBL(f1) VALUES ('-10e-70');
^
-- bad input
INSERT INTO FLOAT4_TBL(f1) VALUES ('');
ERROR: invalid input syntax for type real: ""
LINE 1: INSERT INTO FLOAT4_TBL(f1) VALUES ('');
^
INSERT INTO FLOAT4_TBL(f1) VALUES (' ');
ERROR: invalid input syntax for type real: " "
LINE 1: INSERT INTO FLOAT4_TBL(f1) VALUES (' ');
^
INSERT INTO FLOAT4_TBL(f1) VALUES ('xyz');
ERROR: invalid input syntax for type real: "xyz"
LINE 1: INSERT INTO FLOAT4_TBL(f1) VALUES ('xyz');
^
INSERT INTO FLOAT4_TBL(f1) VALUES ('5.0.0');
ERROR: invalid input syntax for type real: "5.0.0"
LINE 1: INSERT INTO FLOAT4_TBL(f1) VALUES ('5.0.0');
^
INSERT INTO FLOAT4_TBL(f1) VALUES ('5 . 0');
ERROR: invalid input syntax for type real: "5 . 0"
LINE 1: INSERT INTO FLOAT4_TBL(f1) VALUES ('5 . 0');
^
INSERT INTO FLOAT4_TBL(f1) VALUES ('5. 0');
ERROR: invalid input syntax for type real: "5. 0"
LINE 1: INSERT INTO FLOAT4_TBL(f1) VALUES ('5. 0');
^
INSERT INTO FLOAT4_TBL(f1) VALUES (' - 3.0');
ERROR: invalid input syntax for type real: " - 3.0"
LINE 1: INSERT INTO FLOAT4_TBL(f1) VALUES (' - 3.0');
^
INSERT INTO FLOAT4_TBL(f1) VALUES ('123 5');
ERROR: invalid input syntax for type real: "123 5"
LINE 1: INSERT INTO FLOAT4_TBL(f1) VALUES ('123 5');
^
-- special inputs
SELECT 'NaN'::float4;
float4
--------
NaN
(1 row)
SELECT 'nan'::float4;
float4
--------
NaN
(1 row)
SELECT ' NAN '::float4;
float4
--------
NaN
(1 row)
SELECT 'infinity'::float4;
float4
----------
Infinity
(1 row)
SELECT ' -INFINiTY '::float4;
float4
-----------
-Infinity
(1 row)
-- bad special inputs
SELECT 'N A N'::float4;
ERROR: invalid input syntax for type real: "N A N"
LINE 1: SELECT 'N A N'::float4;
^
SELECT 'NaN x'::float4;
ERROR: invalid input syntax for type real: "NaN x"
LINE 1: SELECT 'NaN x'::float4;
^
SELECT ' INFINITY x'::float4;
ERROR: invalid input syntax for type real: " INFINITY x"
LINE 1: SELECT ' INFINITY x'::float4;
^
SELECT 'Infinity'::float4 + 100.0;
?column?
----------
Infinity
(1 row)
SELECT 'Infinity'::float4 / 'Infinity'::float4;
?column?
----------
NaN
(1 row)
SELECT 'nan'::float4 / 'nan'::float4;
?column?
----------
NaN
(1 row)
SELECT 'nan'::numeric::float4;
float4
--------
NaN
(1 row)
SELECT '' AS five, * FROM FLOAT4_TBL;
five | f1
------+--------------
| 0
| 1004.3
| -34.84
| 1.23457e+020
| 1.23457e-020
(5 rows)
SELECT '' AS four, f.* FROM FLOAT4_TBL f WHERE f.f1 <> '1004.3';
four | f1
------+--------------
| 0
| -34.84
| 1.23457e+020
| 1.23457e-020
(4 rows)
SELECT '' AS one, f.* FROM FLOAT4_TBL f WHERE f.f1 = '1004.3';
one | f1
-----+--------
| 1004.3
(1 row)
SELECT '' AS three, f.* FROM FLOAT4_TBL f WHERE '1004.3' > f.f1;
three | f1
-------+--------------
| 0
| -34.84
| 1.23457e-020
(3 rows)
SELECT '' AS three, f.* FROM FLOAT4_TBL f WHERE f.f1 < '1004.3';
three | f1
-------+--------------
| 0
| -34.84
| 1.23457e-020
(3 rows)
SELECT '' AS four, f.* FROM FLOAT4_TBL f WHERE '1004.3' >= f.f1;
four | f1
------+--------------
| 0
| 1004.3
| -34.84
| 1.23457e-020
(4 rows)
SELECT '' AS four, f.* FROM FLOAT4_TBL f WHERE f.f1 <= '1004.3';
four | f1
------+--------------
| 0
| 1004.3
| -34.84
| 1.23457e-020
(4 rows)
SELECT '' AS three, f.f1, f.f1 * '-10' AS x FROM FLOAT4_TBL f
WHERE f.f1 > '0.0';
three | f1 | x
-------+--------------+---------------
| 1004.3 | -10043
| 1.23457e+020 | -1.23457e+021
| 1.23457e-020 | -1.23457e-019
(3 rows)
SELECT '' AS three, f.f1, f.f1 + '-10' AS x FROM FLOAT4_TBL f
WHERE f.f1 > '0.0';
three | f1 | x
-------+--------------+--------------
| 1004.3 | 994.3
| 1.23457e+020 | 1.23457e+020
| 1.23457e-020 | -10
(3 rows)
SELECT '' AS three, f.f1, f.f1 / '-10' AS x FROM FLOAT4_TBL f
WHERE f.f1 > '0.0';
three | f1 | x
-------+--------------+---------------
| 1004.3 | -100.43
| 1.23457e+020 | -1.23457e+019
| 1.23457e-020 | -1.23457e-021
(3 rows)
SELECT '' AS three, f.f1, f.f1 - '-10' AS x FROM FLOAT4_TBL f
WHERE f.f1 > '0.0';
three | f1 | x
-------+--------------+--------------
| 1004.3 | 1014.3
| 1.23457e+020 | 1.23457e+020
| 1.23457e-020 | 10
(3 rows)
-- test divide by zero
SELECT '' AS bad, f.f1 / '0.0' from FLOAT4_TBL f;
ERROR: division by zero
SELECT '' AS five, * FROM FLOAT4_TBL;
five | f1
------+--------------
| 0
| 1004.3
| -34.84
| 1.23457e+020
| 1.23457e-020
(5 rows)
-- test the unary float4abs operator
SELECT '' AS five, f.f1, @f.f1 AS abs_f1 FROM FLOAT4_TBL f;
five | f1 | abs_f1
------+--------------+--------------
| 0 | 0
| 1004.3 | 1004.3
| -34.84 | 34.84
| 1.23457e+020 | 1.23457e+020
| 1.23457e-020 | 1.23457e-020
(5 rows)
UPDATE FLOAT4_TBL
SET f1 = FLOAT4_TBL.f1 * '-1'
WHERE FLOAT4_TBL.f1 > '0.0';
SELECT '' AS five, * FROM FLOAT4_TBL;
five | f1
------+---------------
| 0
| -34.84
| -1004.3
| -1.23457e+020
| -1.23457e-020
(5 rows)

View File

@ -1,586 +0,0 @@
--
-- FLOAT8
--
CREATE TABLE FLOAT8_TBL(f1 float8);
INSERT INTO FLOAT8_TBL(f1) VALUES (' 0.0 ');
INSERT INTO FLOAT8_TBL(f1) VALUES ('1004.30 ');
INSERT INTO FLOAT8_TBL(f1) VALUES (' -34.84');
INSERT INTO FLOAT8_TBL(f1) VALUES ('1.2345678901234e+200');
INSERT INTO FLOAT8_TBL(f1) VALUES ('1.2345678901234e-200');
-- test for underflow and overflow handling
SELECT '10e400'::float8;
ERROR: "10e400" is out of range for type double precision
LINE 1: SELECT '10e400'::float8;
^
SELECT '-10e400'::float8;
ERROR: "-10e400" is out of range for type double precision
LINE 1: SELECT '-10e400'::float8;
^
SELECT '10e-400'::float8;
ERROR: "10e-400" is out of range for type double precision
LINE 1: SELECT '10e-400'::float8;
^
SELECT '-10e-400'::float8;
ERROR: "-10e-400" is out of range for type double precision
LINE 1: SELECT '-10e-400'::float8;
^
-- bad input
INSERT INTO FLOAT8_TBL(f1) VALUES ('');
ERROR: invalid input syntax for type double precision: ""
LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES ('');
^
INSERT INTO FLOAT8_TBL(f1) VALUES (' ');
ERROR: invalid input syntax for type double precision: " "
LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES (' ');
^
INSERT INTO FLOAT8_TBL(f1) VALUES ('xyz');
ERROR: invalid input syntax for type double precision: "xyz"
LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES ('xyz');
^
INSERT INTO FLOAT8_TBL(f1) VALUES ('5.0.0');
ERROR: invalid input syntax for type double precision: "5.0.0"
LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES ('5.0.0');
^
INSERT INTO FLOAT8_TBL(f1) VALUES ('5 . 0');
ERROR: invalid input syntax for type double precision: "5 . 0"
LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES ('5 . 0');
^
INSERT INTO FLOAT8_TBL(f1) VALUES ('5. 0');
ERROR: invalid input syntax for type double precision: "5. 0"
LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES ('5. 0');
^
INSERT INTO FLOAT8_TBL(f1) VALUES (' - 3');
ERROR: invalid input syntax for type double precision: " - 3"
LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES (' - 3');
^
INSERT INTO FLOAT8_TBL(f1) VALUES ('123 5');
ERROR: invalid input syntax for type double precision: "123 5"
LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES ('123 5');
^
-- special inputs
SELECT 'NaN'::float8;
float8
--------
NaN
(1 row)
SELECT 'nan'::float8;
float8
--------
NaN
(1 row)
SELECT ' NAN '::float8;
float8
--------
NaN
(1 row)
SELECT 'infinity'::float8;
float8
----------
Infinity
(1 row)
SELECT ' -INFINiTY '::float8;
float8
-----------
-Infinity
(1 row)
-- bad special inputs
SELECT 'N A N'::float8;
ERROR: invalid input syntax for type double precision: "N A N"
LINE 1: SELECT 'N A N'::float8;
^
SELECT 'NaN x'::float8;
ERROR: invalid input syntax for type double precision: "NaN x"
LINE 1: SELECT 'NaN x'::float8;
^
SELECT ' INFINITY x'::float8;
ERROR: invalid input syntax for type double precision: " INFINITY x"
LINE 1: SELECT ' INFINITY x'::float8;
^
SELECT 'Infinity'::float8 + 100.0;
?column?
----------
Infinity
(1 row)
SELECT 'Infinity'::float8 / 'Infinity'::float8;
?column?
----------
NaN
(1 row)
SELECT 'nan'::float8 / 'nan'::float8;
?column?
----------
NaN
(1 row)
SELECT 'nan'::numeric::float8;
float8
--------
NaN
(1 row)
SELECT '' AS five, * FROM FLOAT8_TBL;
five | f1
------+----------------------
| 0
| 1004.3
| -34.84
| 1.2345678901234e+200
| 1.2345678901234e-200
(5 rows)
SELECT '' AS four, f.* FROM FLOAT8_TBL f WHERE f.f1 <> '1004.3';
four | f1
------+----------------------
| 0
| -34.84
| 1.2345678901234e+200
| 1.2345678901234e-200
(4 rows)
SELECT '' AS one, f.* FROM FLOAT8_TBL f WHERE f.f1 = '1004.3';
one | f1
-----+--------
| 1004.3
(1 row)
SELECT '' AS three, f.* FROM FLOAT8_TBL f WHERE '1004.3' > f.f1;
three | f1
-------+----------------------
| 0
| -34.84
| 1.2345678901234e-200
(3 rows)
SELECT '' AS three, f.* FROM FLOAT8_TBL f WHERE f.f1 < '1004.3';
three | f1
-------+----------------------
| 0
| -34.84
| 1.2345678901234e-200
(3 rows)
SELECT '' AS four, f.* FROM FLOAT8_TBL f WHERE '1004.3' >= f.f1;
four | f1
------+----------------------
| 0
| 1004.3
| -34.84
| 1.2345678901234e-200
(4 rows)
SELECT '' AS four, f.* FROM FLOAT8_TBL f WHERE f.f1 <= '1004.3';
four | f1
------+----------------------
| 0
| 1004.3
| -34.84
| 1.2345678901234e-200
(4 rows)
SELECT '' AS three, f.f1, f.f1 * '-10' AS x
FROM FLOAT8_TBL f
WHERE f.f1 > '0.0';
three | f1 | x
-------+----------------------+-----------------------
| 1004.3 | -10043
| 1.2345678901234e+200 | -1.2345678901234e+201
| 1.2345678901234e-200 | -1.2345678901234e-199
(3 rows)
SELECT '' AS three, f.f1, f.f1 + '-10' AS x
FROM FLOAT8_TBL f
WHERE f.f1 > '0.0';
three | f1 | x
-------+----------------------+----------------------
| 1004.3 | 994.3
| 1.2345678901234e+200 | 1.2345678901234e+200
| 1.2345678901234e-200 | -10
(3 rows)
SELECT '' AS three, f.f1, f.f1 / '-10' AS x
FROM FLOAT8_TBL f
WHERE f.f1 > '0.0';
three | f1 | x
-------+----------------------+-----------------------
| 1004.3 | -100.43
| 1.2345678901234e+200 | -1.2345678901234e+199
| 1.2345678901234e-200 | -1.2345678901234e-201
(3 rows)
SELECT '' AS three, f.f1, f.f1 - '-10' AS x
FROM FLOAT8_TBL f
WHERE f.f1 > '0.0';
three | f1 | x
-------+----------------------+----------------------
| 1004.3 | 1014.3
| 1.2345678901234e+200 | 1.2345678901234e+200
| 1.2345678901234e-200 | 10
(3 rows)
SELECT '' AS one, f.f1 ^ '2.0' AS square_f1
FROM FLOAT8_TBL f where f.f1 = '1004.3';
one | square_f1
-----+------------
| 1008618.49
(1 row)
-- absolute value
SELECT '' AS five, f.f1, @f.f1 AS abs_f1
FROM FLOAT8_TBL f;
five | f1 | abs_f1
------+----------------------+----------------------
| 0 | 0
| 1004.3 | 1004.3
| -34.84 | 34.84
| 1.2345678901234e+200 | 1.2345678901234e+200
| 1.2345678901234e-200 | 1.2345678901234e-200
(5 rows)
-- truncate
SELECT '' AS five, f.f1, trunc(f.f1) AS trunc_f1
FROM FLOAT8_TBL f;
five | f1 | trunc_f1
------+----------------------+----------------------
| 0 | 0
| 1004.3 | 1004
| -34.84 | -34
| 1.2345678901234e+200 | 1.2345678901234e+200
| 1.2345678901234e-200 | 0
(5 rows)
-- round
SELECT '' AS five, f.f1, round(f.f1) AS round_f1
FROM FLOAT8_TBL f;
five | f1 | round_f1
------+----------------------+----------------------
| 0 | 0
| 1004.3 | 1004
| -34.84 | -35
| 1.2345678901234e+200 | 1.2345678901234e+200
| 1.2345678901234e-200 | 0
(5 rows)
-- ceil / ceiling
select ceil(f1) as ceil_f1 from float8_tbl f;
ceil_f1
----------------------
0
1005
-34
1.2345678901234e+200
1
(5 rows)
select ceiling(f1) as ceiling_f1 from float8_tbl f;
ceiling_f1
----------------------
0
1005
-34
1.2345678901234e+200
1
(5 rows)
-- floor
select floor(f1) as floor_f1 from float8_tbl f;
floor_f1
----------------------
0
1004
-35
1.2345678901234e+200
0
(5 rows)
-- sign
select sign(f1) as sign_f1 from float8_tbl f;
sign_f1
---------
0
1
-1
1
1
(5 rows)
-- square root
SELECT sqrt(float8 '64') AS eight;
eight
-------
8
(1 row)
SELECT |/ float8 '64' AS eight;
eight
-------
8
(1 row)
SELECT '' AS three, f.f1, |/f.f1 AS sqrt_f1
FROM FLOAT8_TBL f
WHERE f.f1 > '0.0';
three | f1 | sqrt_f1
-------+----------------------+-----------------------
| 1004.3 | 31.6906926399535
| 1.2345678901234e+200 | 1.11111110611109e+100
| 1.2345678901234e-200 | 1.11111110611109e-100
(3 rows)
-- power
SELECT power(float8 '144', float8 '0.5');
power
-------
12
(1 row)
SELECT power(float8 'NaN', float8 '0.5');
power
-------
NaN
(1 row)
SELECT power(float8 '144', float8 'NaN');
power
-------
NaN
(1 row)
SELECT power(float8 'NaN', float8 'NaN');
power
-------
NaN
(1 row)
SELECT power(float8 '-1', float8 'NaN');
power
-------
NaN
(1 row)
SELECT power(float8 '1', float8 'NaN');
power
-------
1
(1 row)
SELECT power(float8 'NaN', float8 '0');
power
-------
1
(1 row)
-- take exp of ln(f.f1)
SELECT '' AS three, f.f1, exp(ln(f.f1)) AS exp_ln_f1
FROM FLOAT8_TBL f
WHERE f.f1 > '0.0';
three | f1 | exp_ln_f1
-------+----------------------+-----------------------
| 1004.3 | 1004.3
| 1.2345678901234e+200 | 1.23456789012338e+200
| 1.2345678901234e-200 | 1.23456789012339e-200
(3 rows)
-- cube root
SELECT ||/ float8 '27' AS three;
three
-------
3
(1 row)
SELECT '' AS five, f.f1, ||/f.f1 AS cbrt_f1 FROM FLOAT8_TBL f;
five | f1 | cbrt_f1
------+----------------------+-----------------------
| 0 | 0
| 1004.3 | 10.014312837827
| -34.84 | -3.26607421344208
| 1.2345678901234e+200 | 4.97933859234765e+066
| 1.2345678901234e-200 | 2.3112042409018e-067
(5 rows)
SELECT '' AS five, * FROM FLOAT8_TBL;
five | f1
------+----------------------
| 0
| 1004.3
| -34.84
| 1.2345678901234e+200
| 1.2345678901234e-200
(5 rows)
UPDATE FLOAT8_TBL
SET f1 = FLOAT8_TBL.f1 * '-1'
WHERE FLOAT8_TBL.f1 > '0.0';
SELECT '' AS bad, f.f1 * '1e200' from FLOAT8_TBL f;
ERROR: value out of range: overflow
SELECT '' AS bad, f.f1 ^ '1e200' from FLOAT8_TBL f;
ERROR: value out of range: overflow
SELECT 0 ^ 0 + 0 ^ 1 + 0 ^ 0.0 + 0 ^ 0.5;
?column?
----------
2
(1 row)
SELECT '' AS bad, ln(f.f1) from FLOAT8_TBL f where f.f1 = '0.0' ;
ERROR: cannot take logarithm of zero
SELECT '' AS bad, ln(f.f1) from FLOAT8_TBL f where f.f1 < '0.0' ;
ERROR: cannot take logarithm of a negative number
SELECT '' AS bad, exp(f.f1) from FLOAT8_TBL f;
ERROR: value out of range: underflow
SELECT '' AS bad, f.f1 / '0.0' from FLOAT8_TBL f;
ERROR: division by zero
SELECT '' AS five, * FROM FLOAT8_TBL;
five | f1
------+-----------------------
| 0
| -34.84
| -1004.3
| -1.2345678901234e+200
| -1.2345678901234e-200
(5 rows)
-- test for over- and underflow
INSERT INTO FLOAT8_TBL(f1) VALUES ('10e400');
ERROR: "10e400" is out of range for type double precision
LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES ('10e400');
^
INSERT INTO FLOAT8_TBL(f1) VALUES ('-10e400');
ERROR: "-10e400" is out of range for type double precision
LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES ('-10e400');
^
INSERT INTO FLOAT8_TBL(f1) VALUES ('10e-400');
ERROR: "10e-400" is out of range for type double precision
LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES ('10e-400');
^
INSERT INTO FLOAT8_TBL(f1) VALUES ('-10e-400');
ERROR: "-10e-400" is out of range for type double precision
LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES ('-10e-400');
^
-- maintain external table consistency across platforms
-- delete all values and reinsert well-behaved ones
DELETE FROM FLOAT8_TBL;
INSERT INTO FLOAT8_TBL(f1) VALUES ('0.0');
INSERT INTO FLOAT8_TBL(f1) VALUES ('-34.84');
INSERT INTO FLOAT8_TBL(f1) VALUES ('-1004.30');
INSERT INTO FLOAT8_TBL(f1) VALUES ('-1.2345678901234e+200');
INSERT INTO FLOAT8_TBL(f1) VALUES ('-1.2345678901234e-200');
SELECT '' AS five, * FROM FLOAT8_TBL;
five | f1
------+-----------------------
| 0
| -34.84
| -1004.3
| -1.2345678901234e+200
| -1.2345678901234e-200
(5 rows)
-- test exact cases for trigonometric functions in degrees
SET extra_float_digits = 3;
SELECT x,
sind(x),
sind(x) IN (-1,-0.5,0,0.5,1) AS sind_exact
FROM (VALUES (0), (30), (90), (150), (180),
(210), (270), (330), (360)) AS t(x);
x | sind | sind_exact
-----+------+------------
0 | 0 | t
30 | 0.5 | t
90 | 1 | t
150 | 0.5 | t
180 | 0 | t
210 | -0.5 | t
270 | -1 | t
330 | -0.5 | t
360 | 0 | t
(9 rows)
SELECT x,
cosd(x),
cosd(x) IN (-1,-0.5,0,0.5,1) AS cosd_exact
FROM (VALUES (0), (60), (90), (120), (180),
(240), (270), (300), (360)) AS t(x);
x | cosd | cosd_exact
-----+------+------------
0 | 1 | t
60 | 0.5 | t
90 | 0 | t
120 | -0.5 | t
180 | -1 | t
240 | -0.5 | t
270 | 0 | t
300 | 0.5 | t
360 | 1 | t
(9 rows)
SELECT x,
tand(x),
tand(x) IN ('-Infinity'::float8,-1,0,
1,'Infinity'::float8) AS tand_exact,
cotd(x),
cotd(x) IN ('-Infinity'::float8,-1,0,
1,'Infinity'::float8) AS cotd_exact
FROM (VALUES (0), (45), (90), (135), (180),
(225), (270), (315), (360)) AS t(x);
x | tand | tand_exact | cotd | cotd_exact
-----+-----------+------------+-----------+------------
0 | 0 | t | Infinity | t
45 | 1 | t | 1 | t
90 | Infinity | t | 0 | t
135 | -1 | t | -1 | t
180 | 0 | t | -Infinity | t
225 | 1 | t | 1 | t
270 | -Infinity | t | 0 | t
315 | -1 | t | -1 | t
360 | 0 | t | Infinity | t
(9 rows)
SELECT x,
asind(x),
asind(x) IN (-90,-30,0,30,90) AS asind_exact,
acosd(x),
acosd(x) IN (0,60,90,120,180) AS acosd_exact
FROM (VALUES (-1), (-0.5), (0), (0.5), (1)) AS t(x);
x | asind | asind_exact | acosd | acosd_exact
------+-------+-------------+-------+-------------
-1 | -90 | t | 180 | t
-0.5 | -30 | t | 120 | t
0 | 0 | t | 90 | t
0.5 | 30 | t | 60 | t
1 | 90 | t | 0 | t
(5 rows)
SELECT x,
atand(x),
atand(x) IN (-90,-45,0,45,90) AS atand_exact
FROM (VALUES ('-Infinity'::float8), (-1), (0), (1),
('Infinity'::float8)) AS t(x);
x | atand | atand_exact
-----------+-------+-------------
-Infinity | -90 | t
-1 | -45 | t
0 | 0 | t
1 | 45 | t
Infinity | 90 | t
(5 rows)
SELECT x, y,
atan2d(y, x),
atan2d(y, x) IN (-90,0,90,180) AS atan2d_exact
FROM (SELECT 10*cosd(a), 10*sind(a)
FROM generate_series(0, 360, 90) AS t(a)) AS t(x,y);
x | y | atan2d | atan2d_exact
-----+-----+--------+--------------
10 | 0 | 0 | t
0 | 10 | 90 | t
-10 | 0 | 180 | t
0 | -10 | -90 | t
10 | 0 | 0 | t
(5 rows)
RESET extra_float_digits;

File diff suppressed because it is too large Load Diff

View File

@ -1,888 +0,0 @@
--
-- INT8
-- Test int8 64-bit integers.
--
CREATE TABLE INT8_TBL(q1 int8, q2 int8);
INSERT INTO INT8_TBL VALUES(' 123 ',' 456');
INSERT INTO INT8_TBL VALUES('123 ','4567890123456789');
INSERT INTO INT8_TBL VALUES('4567890123456789','123');
INSERT INTO INT8_TBL VALUES(+4567890123456789,'4567890123456789');
INSERT INTO INT8_TBL VALUES('+4567890123456789','-4567890123456789');
-- bad inputs
INSERT INTO INT8_TBL(q1) VALUES (' ');
ERROR: invalid input syntax for type bigint: " "
LINE 1: INSERT INTO INT8_TBL(q1) VALUES (' ');
^
INSERT INTO INT8_TBL(q1) VALUES ('xxx');
ERROR: invalid input syntax for type bigint: "xxx"
LINE 1: INSERT INTO INT8_TBL(q1) VALUES ('xxx');
^
INSERT INTO INT8_TBL(q1) VALUES ('3908203590239580293850293850329485');
ERROR: value "3908203590239580293850293850329485" is out of range for type bigint
LINE 1: INSERT INTO INT8_TBL(q1) VALUES ('39082035902395802938502938...
^
INSERT INTO INT8_TBL(q1) VALUES ('-1204982019841029840928340329840934');
ERROR: value "-1204982019841029840928340329840934" is out of range for type bigint
LINE 1: INSERT INTO INT8_TBL(q1) VALUES ('-1204982019841029840928340...
^
INSERT INTO INT8_TBL(q1) VALUES ('- 123');
ERROR: invalid input syntax for type bigint: "- 123"
LINE 1: INSERT INTO INT8_TBL(q1) VALUES ('- 123');
^
INSERT INTO INT8_TBL(q1) VALUES (' 345 5');
ERROR: invalid input syntax for type bigint: " 345 5"
LINE 1: INSERT INTO INT8_TBL(q1) VALUES (' 345 5');
^
INSERT INTO INT8_TBL(q1) VALUES ('');
ERROR: invalid input syntax for type bigint: ""
LINE 1: INSERT INTO INT8_TBL(q1) VALUES ('');
^
SELECT * FROM INT8_TBL;
q1 | q2
------------------+-------------------
123 | 456
123 | 4567890123456789
4567890123456789 | 123
4567890123456789 | 4567890123456789
4567890123456789 | -4567890123456789
(5 rows)
-- int8/int8 cmp
SELECT * FROM INT8_TBL WHERE q2 = 4567890123456789;
q1 | q2
------------------+------------------
123 | 4567890123456789
4567890123456789 | 4567890123456789
(2 rows)
SELECT * FROM INT8_TBL WHERE q2 <> 4567890123456789;
q1 | q2
------------------+-------------------
123 | 456
4567890123456789 | 123
4567890123456789 | -4567890123456789
(3 rows)
SELECT * FROM INT8_TBL WHERE q2 < 4567890123456789;
q1 | q2
------------------+-------------------
123 | 456
4567890123456789 | 123
4567890123456789 | -4567890123456789
(3 rows)
SELECT * FROM INT8_TBL WHERE q2 > 4567890123456789;
q1 | q2
----+----
(0 rows)
SELECT * FROM INT8_TBL WHERE q2 <= 4567890123456789;
q1 | q2
------------------+-------------------
123 | 456
123 | 4567890123456789
4567890123456789 | 123
4567890123456789 | 4567890123456789
4567890123456789 | -4567890123456789
(5 rows)
SELECT * FROM INT8_TBL WHERE q2 >= 4567890123456789;
q1 | q2
------------------+------------------
123 | 4567890123456789
4567890123456789 | 4567890123456789
(2 rows)
-- int8/int4 cmp
SELECT * FROM INT8_TBL WHERE q2 = 456;
q1 | q2
-----+-----
123 | 456
(1 row)
SELECT * FROM INT8_TBL WHERE q2 <> 456;
q1 | q2
------------------+-------------------
123 | 4567890123456789
4567890123456789 | 123
4567890123456789 | 4567890123456789
4567890123456789 | -4567890123456789
(4 rows)
SELECT * FROM INT8_TBL WHERE q2 < 456;
q1 | q2
------------------+-------------------
4567890123456789 | 123
4567890123456789 | -4567890123456789
(2 rows)
SELECT * FROM INT8_TBL WHERE q2 > 456;
q1 | q2
------------------+------------------
123 | 4567890123456789
4567890123456789 | 4567890123456789
(2 rows)
SELECT * FROM INT8_TBL WHERE q2 <= 456;
q1 | q2
------------------+-------------------
123 | 456
4567890123456789 | 123
4567890123456789 | -4567890123456789
(3 rows)
SELECT * FROM INT8_TBL WHERE q2 >= 456;
q1 | q2
------------------+------------------
123 | 456
123 | 4567890123456789
4567890123456789 | 4567890123456789
(3 rows)
-- int4/int8 cmp
SELECT * FROM INT8_TBL WHERE 123 = q1;
q1 | q2
-----+------------------
123 | 456
123 | 4567890123456789
(2 rows)
SELECT * FROM INT8_TBL WHERE 123 <> q1;
q1 | q2
------------------+-------------------
4567890123456789 | 123
4567890123456789 | 4567890123456789
4567890123456789 | -4567890123456789
(3 rows)
SELECT * FROM INT8_TBL WHERE 123 < q1;
q1 | q2
------------------+-------------------
4567890123456789 | 123
4567890123456789 | 4567890123456789
4567890123456789 | -4567890123456789
(3 rows)
SELECT * FROM INT8_TBL WHERE 123 > q1;
q1 | q2
----+----
(0 rows)
SELECT * FROM INT8_TBL WHERE 123 <= q1;
q1 | q2
------------------+-------------------
123 | 456
123 | 4567890123456789
4567890123456789 | 123
4567890123456789 | 4567890123456789
4567890123456789 | -4567890123456789
(5 rows)
SELECT * FROM INT8_TBL WHERE 123 >= q1;
q1 | q2
-----+------------------
123 | 456
123 | 4567890123456789
(2 rows)
-- int8/int2 cmp
SELECT * FROM INT8_TBL WHERE q2 = '456'::int2;
q1 | q2
-----+-----
123 | 456
(1 row)
SELECT * FROM INT8_TBL WHERE q2 <> '456'::int2;
q1 | q2
------------------+-------------------
123 | 4567890123456789
4567890123456789 | 123
4567890123456789 | 4567890123456789
4567890123456789 | -4567890123456789
(4 rows)
SELECT * FROM INT8_TBL WHERE q2 < '456'::int2;
q1 | q2
------------------+-------------------
4567890123456789 | 123
4567890123456789 | -4567890123456789
(2 rows)
SELECT * FROM INT8_TBL WHERE q2 > '456'::int2;
q1 | q2
------------------+------------------
123 | 4567890123456789
4567890123456789 | 4567890123456789
(2 rows)
SELECT * FROM INT8_TBL WHERE q2 <= '456'::int2;
q1 | q2
------------------+-------------------
123 | 456
4567890123456789 | 123
4567890123456789 | -4567890123456789
(3 rows)
SELECT * FROM INT8_TBL WHERE q2 >= '456'::int2;
q1 | q2
------------------+------------------
123 | 456
123 | 4567890123456789
4567890123456789 | 4567890123456789
(3 rows)
-- int2/int8 cmp
SELECT * FROM INT8_TBL WHERE '123'::int2 = q1;
q1 | q2
-----+------------------
123 | 456
123 | 4567890123456789
(2 rows)
SELECT * FROM INT8_TBL WHERE '123'::int2 <> q1;
q1 | q2
------------------+-------------------
4567890123456789 | 123
4567890123456789 | 4567890123456789
4567890123456789 | -4567890123456789
(3 rows)
SELECT * FROM INT8_TBL WHERE '123'::int2 < q1;
q1 | q2
------------------+-------------------
4567890123456789 | 123
4567890123456789 | 4567890123456789
4567890123456789 | -4567890123456789
(3 rows)
SELECT * FROM INT8_TBL WHERE '123'::int2 > q1;
q1 | q2
----+----
(0 rows)
SELECT * FROM INT8_TBL WHERE '123'::int2 <= q1;
q1 | q2
------------------+-------------------
123 | 456
123 | 4567890123456789
4567890123456789 | 123
4567890123456789 | 4567890123456789
4567890123456789 | -4567890123456789
(5 rows)
SELECT * FROM INT8_TBL WHERE '123'::int2 >= q1;
q1 | q2
-----+------------------
123 | 456
123 | 4567890123456789
(2 rows)
SELECT '' AS five, q1 AS plus, -q1 AS minus FROM INT8_TBL;
five | plus | minus
------+------------------+-------------------
| 123 | -123
| 123 | -123
| 4567890123456789 | -4567890123456789
| 4567890123456789 | -4567890123456789
| 4567890123456789 | -4567890123456789
(5 rows)
SELECT '' AS five, q1, q2, q1 + q2 AS plus FROM INT8_TBL;
five | q1 | q2 | plus
------+------------------+-------------------+------------------
| 123 | 456 | 579
| 123 | 4567890123456789 | 4567890123456912
| 4567890123456789 | 123 | 4567890123456912
| 4567890123456789 | 4567890123456789 | 9135780246913578
| 4567890123456789 | -4567890123456789 | 0
(5 rows)
SELECT '' AS five, q1, q2, q1 - q2 AS minus FROM INT8_TBL;
five | q1 | q2 | minus
------+------------------+-------------------+-------------------
| 123 | 456 | -333
| 123 | 4567890123456789 | -4567890123456666
| 4567890123456789 | 123 | 4567890123456666
| 4567890123456789 | 4567890123456789 | 0
| 4567890123456789 | -4567890123456789 | 9135780246913578
(5 rows)
SELECT '' AS three, q1, q2, q1 * q2 AS multiply FROM INT8_TBL;
ERROR: bigint out of range
SELECT '' AS three, q1, q2, q1 * q2 AS multiply FROM INT8_TBL
WHERE q1 < 1000 or (q2 > 0 and q2 < 1000);
three | q1 | q2 | multiply
-------+------------------+------------------+--------------------
| 123 | 456 | 56088
| 123 | 4567890123456789 | 561850485185185047
| 4567890123456789 | 123 | 561850485185185047
(3 rows)
SELECT '' AS five, q1, q2, q1 / q2 AS divide, q1 % q2 AS mod FROM INT8_TBL;
five | q1 | q2 | divide | mod
------+------------------+-------------------+----------------+-----
| 123 | 456 | 0 | 123
| 123 | 4567890123456789 | 0 | 123
| 4567890123456789 | 123 | 37137318076884 | 57
| 4567890123456789 | 4567890123456789 | 1 | 0
| 4567890123456789 | -4567890123456789 | -1 | 0
(5 rows)
SELECT '' AS five, q1, float8(q1) FROM INT8_TBL;
five | q1 | float8
------+------------------+-----------------------
| 123 | 123
| 123 | 123
| 4567890123456789 | 4.56789012345679e+015
| 4567890123456789 | 4.56789012345679e+015
| 4567890123456789 | 4.56789012345679e+015
(5 rows)
SELECT '' AS five, q2, float8(q2) FROM INT8_TBL;
five | q2 | float8
------+-------------------+------------------------
| 456 | 456
| 4567890123456789 | 4.56789012345679e+015
| 123 | 123
| 4567890123456789 | 4.56789012345679e+015
| -4567890123456789 | -4.56789012345679e+015
(5 rows)
SELECT 37 + q1 AS plus4 FROM INT8_TBL;
plus4
------------------
160
160
4567890123456826
4567890123456826
4567890123456826
(5 rows)
SELECT 37 - q1 AS minus4 FROM INT8_TBL;
minus4
-------------------
-86
-86
-4567890123456752
-4567890123456752
-4567890123456752
(5 rows)
SELECT '' AS five, 2 * q1 AS "twice int4" FROM INT8_TBL;
five | twice int4
------+------------------
| 246
| 246
| 9135780246913578
| 9135780246913578
| 9135780246913578
(5 rows)
SELECT '' AS five, q1 * 2 AS "twice int4" FROM INT8_TBL;
five | twice int4
------+------------------
| 246
| 246
| 9135780246913578
| 9135780246913578
| 9135780246913578
(5 rows)
-- int8 op int4
SELECT q1 + 42::int4 AS "8plus4", q1 - 42::int4 AS "8minus4", q1 * 42::int4 AS "8mul4", q1 / 42::int4 AS "8div4" FROM INT8_TBL;
8plus4 | 8minus4 | 8mul4 | 8div4
------------------+------------------+--------------------+-----------------
165 | 81 | 5166 | 2
165 | 81 | 5166 | 2
4567890123456831 | 4567890123456747 | 191851385185185138 | 108759288653733
4567890123456831 | 4567890123456747 | 191851385185185138 | 108759288653733
4567890123456831 | 4567890123456747 | 191851385185185138 | 108759288653733
(5 rows)
-- int4 op int8
SELECT 246::int4 + q1 AS "4plus8", 246::int4 - q1 AS "4minus8", 246::int4 * q1 AS "4mul8", 246::int4 / q1 AS "4div8" FROM INT8_TBL;
4plus8 | 4minus8 | 4mul8 | 4div8
------------------+-------------------+---------------------+-------
369 | 123 | 30258 | 2
369 | 123 | 30258 | 2
4567890123457035 | -4567890123456543 | 1123700970370370094 | 0
4567890123457035 | -4567890123456543 | 1123700970370370094 | 0
4567890123457035 | -4567890123456543 | 1123700970370370094 | 0
(5 rows)
-- int8 op int2
SELECT q1 + 42::int2 AS "8plus2", q1 - 42::int2 AS "8minus2", q1 * 42::int2 AS "8mul2", q1 / 42::int2 AS "8div2" FROM INT8_TBL;
8plus2 | 8minus2 | 8mul2 | 8div2
------------------+------------------+--------------------+-----------------
165 | 81 | 5166 | 2
165 | 81 | 5166 | 2
4567890123456831 | 4567890123456747 | 191851385185185138 | 108759288653733
4567890123456831 | 4567890123456747 | 191851385185185138 | 108759288653733
4567890123456831 | 4567890123456747 | 191851385185185138 | 108759288653733
(5 rows)
-- int2 op int8
SELECT 246::int2 + q1 AS "2plus8", 246::int2 - q1 AS "2minus8", 246::int2 * q1 AS "2mul8", 246::int2 / q1 AS "2div8" FROM INT8_TBL;
2plus8 | 2minus8 | 2mul8 | 2div8
------------------+-------------------+---------------------+-------
369 | 123 | 30258 | 2
369 | 123 | 30258 | 2
4567890123457035 | -4567890123456543 | 1123700970370370094 | 0
4567890123457035 | -4567890123456543 | 1123700970370370094 | 0
4567890123457035 | -4567890123456543 | 1123700970370370094 | 0
(5 rows)
SELECT q2, abs(q2) FROM INT8_TBL;
q2 | abs
-------------------+------------------
456 | 456
4567890123456789 | 4567890123456789
123 | 123
4567890123456789 | 4567890123456789
-4567890123456789 | 4567890123456789
(5 rows)
SELECT min(q1), min(q2) FROM INT8_TBL;
min | min
-----+-------------------
123 | -4567890123456789
(1 row)
SELECT max(q1), max(q2) FROM INT8_TBL;
max | max
------------------+------------------
4567890123456789 | 4567890123456789
(1 row)
-- TO_CHAR()
--
SELECT '' AS to_char_1, to_char(q1, '9G999G999G999G999G999'), to_char(q2, '9,999,999,999,999,999')
FROM INT8_TBL;
to_char_1 | to_char | to_char
-----------+------------------------+------------------------
| 123 | 456
| 123 | 4,567,890,123,456,789
| 4,567,890,123,456,789 | 123
| 4,567,890,123,456,789 | 4,567,890,123,456,789
| 4,567,890,123,456,789 | -4,567,890,123,456,789
(5 rows)
SELECT '' AS to_char_2, to_char(q1, '9G999G999G999G999G999D999G999'), to_char(q2, '9,999,999,999,999,999.999,999')
FROM INT8_TBL;
to_char_2 | to_char | to_char
-----------+--------------------------------+--------------------------------
| 123.000,000 | 456.000,000
| 123.000,000 | 4,567,890,123,456,789.000,000
| 4,567,890,123,456,789.000,000 | 123.000,000
| 4,567,890,123,456,789.000,000 | 4,567,890,123,456,789.000,000
| 4,567,890,123,456,789.000,000 | -4,567,890,123,456,789.000,000
(5 rows)
SELECT '' AS to_char_3, to_char( (q1 * -1), '9999999999999999PR'), to_char( (q2 * -1), '9999999999999999.999PR')
FROM INT8_TBL;
to_char_3 | to_char | to_char
-----------+--------------------+------------------------
| <123> | <456.000>
| <123> | <4567890123456789.000>
| <4567890123456789> | <123.000>
| <4567890123456789> | <4567890123456789.000>
| <4567890123456789> | 4567890123456789.000
(5 rows)
SELECT '' AS to_char_4, to_char( (q1 * -1), '9999999999999999S'), to_char( (q2 * -1), 'S9999999999999999')
FROM INT8_TBL;
to_char_4 | to_char | to_char
-----------+-------------------+-------------------
| 123- | -456
| 123- | -4567890123456789
| 4567890123456789- | -123
| 4567890123456789- | -4567890123456789
| 4567890123456789- | +4567890123456789
(5 rows)
SELECT '' AS to_char_5, to_char(q2, 'MI9999999999999999') FROM INT8_TBL;
to_char_5 | to_char
-----------+-------------------
| 456
| 4567890123456789
| 123
| 4567890123456789
| -4567890123456789
(5 rows)
SELECT '' AS to_char_6, to_char(q2, 'FMS9999999999999999') FROM INT8_TBL;
to_char_6 | to_char
-----------+-------------------
| +456
| +4567890123456789
| +123
| +4567890123456789
| -4567890123456789
(5 rows)
SELECT '' AS to_char_7, to_char(q2, 'FM9999999999999999THPR') FROM INT8_TBL;
to_char_7 | to_char
-----------+--------------------
| 456TH
| 4567890123456789TH
| 123RD
| 4567890123456789TH
| <4567890123456789>
(5 rows)
SELECT '' AS to_char_8, to_char(q2, 'SG9999999999999999th') FROM INT8_TBL;
to_char_8 | to_char
-----------+---------------------
| + 456th
| +4567890123456789th
| + 123rd
| +4567890123456789th
| -4567890123456789
(5 rows)
SELECT '' AS to_char_9, to_char(q2, '0999999999999999') FROM INT8_TBL;
to_char_9 | to_char
-----------+-------------------
| 0000000000000456
| 4567890123456789
| 0000000000000123
| 4567890123456789
| -4567890123456789
(5 rows)
SELECT '' AS to_char_10, to_char(q2, 'S0999999999999999') FROM INT8_TBL;
to_char_10 | to_char
------------+-------------------
| +0000000000000456
| +4567890123456789
| +0000000000000123
| +4567890123456789
| -4567890123456789
(5 rows)
SELECT '' AS to_char_11, to_char(q2, 'FM0999999999999999') FROM INT8_TBL;
to_char_11 | to_char
------------+-------------------
| 0000000000000456
| 4567890123456789
| 0000000000000123
| 4567890123456789
| -4567890123456789
(5 rows)
SELECT '' AS to_char_12, to_char(q2, 'FM9999999999999999.000') FROM INT8_TBL;
to_char_12 | to_char
------------+-----------------------
| 456.000
| 4567890123456789.000
| 123.000
| 4567890123456789.000
| -4567890123456789.000
(5 rows)
SELECT '' AS to_char_13, to_char(q2, 'L9999999999999999.000') FROM INT8_TBL;
to_char_13 | to_char
------------+------------------------
| 456.000
| 4567890123456789.000
| 123.000
| 4567890123456789.000
| -4567890123456789.000
(5 rows)
SELECT '' AS to_char_14, to_char(q2, 'FM9999999999999999.999') FROM INT8_TBL;
to_char_14 | to_char
------------+--------------------
| 456.
| 4567890123456789.
| 123.
| 4567890123456789.
| -4567890123456789.
(5 rows)
SELECT '' AS to_char_15, to_char(q2, 'S 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 . 9 9 9') FROM INT8_TBL;
to_char_15 | to_char
------------+-------------------------------------------
| +4 5 6 . 0 0 0
| +4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 . 0 0 0
| +1 2 3 . 0 0 0
| +4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 . 0 0 0
| -4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 . 0 0 0
(5 rows)
SELECT '' AS to_char_16, to_char(q2, E'99999 "text" 9999 "9999" 999 "\\"text between quote marks\\"" 9999') FROM INT8_TBL;
to_char_16 | to_char
------------+-----------------------------------------------------------
| text 9999 "text between quote marks" 456
| 45678 text 9012 9999 345 "text between quote marks" 6789
| text 9999 "text between quote marks" 123
| 45678 text 9012 9999 345 "text between quote marks" 6789
| -45678 text 9012 9999 345 "text between quote marks" 6789
(5 rows)
SELECT '' AS to_char_17, to_char(q2, '999999SG9999999999') FROM INT8_TBL;
to_char_17 | to_char
------------+-------------------
| + 456
| 456789+0123456789
| + 123
| 456789+0123456789
| 456789-0123456789
(5 rows)
-- check min/max values and overflow behavior
select '-9223372036854775808'::int8;
int8
----------------------
-9223372036854775808
(1 row)
select '-9223372036854775809'::int8;
ERROR: value "-9223372036854775809" is out of range for type bigint
LINE 1: select '-9223372036854775809'::int8;
^
select '9223372036854775807'::int8;
int8
---------------------
9223372036854775807
(1 row)
select '9223372036854775808'::int8;
ERROR: value "9223372036854775808" is out of range for type bigint
LINE 1: select '9223372036854775808'::int8;
^
select -('-9223372036854775807'::int8);
?column?
---------------------
9223372036854775807
(1 row)
select -('-9223372036854775808'::int8);
ERROR: bigint out of range
select '9223372036854775800'::int8 + '9223372036854775800'::int8;
ERROR: bigint out of range
select '-9223372036854775800'::int8 + '-9223372036854775800'::int8;
ERROR: bigint out of range
select '9223372036854775800'::int8 - '-9223372036854775800'::int8;
ERROR: bigint out of range
select '-9223372036854775800'::int8 - '9223372036854775800'::int8;
ERROR: bigint out of range
select '9223372036854775800'::int8 * '9223372036854775800'::int8;
ERROR: bigint out of range
select '9223372036854775800'::int8 / '0'::int8;
ERROR: division by zero
select '9223372036854775800'::int8 % '0'::int8;
ERROR: division by zero
select abs('-9223372036854775808'::int8);
ERROR: bigint out of range
select '9223372036854775800'::int8 + '100'::int4;
ERROR: bigint out of range
select '-9223372036854775800'::int8 - '100'::int4;
ERROR: bigint out of range
select '9223372036854775800'::int8 * '100'::int4;
ERROR: bigint out of range
select '100'::int4 + '9223372036854775800'::int8;
ERROR: bigint out of range
select '-100'::int4 - '9223372036854775800'::int8;
ERROR: bigint out of range
select '100'::int4 * '9223372036854775800'::int8;
ERROR: bigint out of range
select '9223372036854775800'::int8 + '100'::int2;
ERROR: bigint out of range
select '-9223372036854775800'::int8 - '100'::int2;
ERROR: bigint out of range
select '9223372036854775800'::int8 * '100'::int2;
ERROR: bigint out of range
select '-9223372036854775808'::int8 / '0'::int2;
ERROR: division by zero
select '100'::int2 + '9223372036854775800'::int8;
ERROR: bigint out of range
select '-100'::int2 - '9223372036854775800'::int8;
ERROR: bigint out of range
select '100'::int2 * '9223372036854775800'::int8;
ERROR: bigint out of range
select '100'::int2 / '0'::int8;
ERROR: division by zero
SELECT CAST(q1 AS int4) FROM int8_tbl WHERE q2 = 456;
q1
-----
123
(1 row)
SELECT CAST(q1 AS int4) FROM int8_tbl WHERE q2 <> 456;
ERROR: integer out of range
SELECT CAST(q1 AS int2) FROM int8_tbl WHERE q2 = 456;
q1
-----
123
(1 row)
SELECT CAST(q1 AS int2) FROM int8_tbl WHERE q2 <> 456;
ERROR: smallint out of range
SELECT CAST('42'::int2 AS int8), CAST('-37'::int2 AS int8);
int8 | int8
------+------
42 | -37
(1 row)
SELECT CAST(q1 AS float4), CAST(q2 AS float8) FROM INT8_TBL;
q1 | q2
--------------+------------------------
123 | 456
123 | 4.56789012345679e+015
4.56789e+015 | 123
4.56789e+015 | 4.56789012345679e+015
4.56789e+015 | -4.56789012345679e+015
(5 rows)
SELECT CAST('36854775807.0'::float4 AS int8);
int8
-------------
36854775808
(1 row)
SELECT CAST('922337203685477580700.0'::float8 AS int8);
ERROR: bigint out of range
SELECT CAST(q1 AS oid) FROM INT8_TBL;
ERROR: OID out of range
SELECT oid::int8 FROM pg_class WHERE relname = 'pg_class';
oid
------
1259
(1 row)
-- bit operations
SELECT q1, q2, q1 & q2 AS "and", q1 | q2 AS "or", q1 # q2 AS "xor", ~q1 AS "not" FROM INT8_TBL;
q1 | q2 | and | or | xor | not
------------------+-------------------+------------------+------------------+------------------+-------------------
123 | 456 | 72 | 507 | 435 | -124
123 | 4567890123456789 | 17 | 4567890123456895 | 4567890123456878 | -124
4567890123456789 | 123 | 17 | 4567890123456895 | 4567890123456878 | -4567890123456790
4567890123456789 | 4567890123456789 | 4567890123456789 | 4567890123456789 | 0 | -4567890123456790
4567890123456789 | -4567890123456789 | 1 | -1 | -2 | -4567890123456790
(5 rows)
SELECT q1, q1 << 2 AS "shl", q1 >> 3 AS "shr" FROM INT8_TBL;
q1 | shl | shr
------------------+-------------------+-----------------
123 | 492 | 15
123 | 492 | 15
4567890123456789 | 18271560493827156 | 570986265432098
4567890123456789 | 18271560493827156 | 570986265432098
4567890123456789 | 18271560493827156 | 570986265432098
(5 rows)
-- generate_series
SELECT * FROM generate_series('+4567890123456789'::int8, '+4567890123456799'::int8);
generate_series
------------------
4567890123456789
4567890123456790
4567890123456791
4567890123456792
4567890123456793
4567890123456794
4567890123456795
4567890123456796
4567890123456797
4567890123456798
4567890123456799
(11 rows)
SELECT * FROM generate_series('+4567890123456789'::int8, '+4567890123456799'::int8, 0);
ERROR: step size cannot equal zero
SELECT * FROM generate_series('+4567890123456789'::int8, '+4567890123456799'::int8, 2);
generate_series
------------------
4567890123456789
4567890123456791
4567890123456793
4567890123456795
4567890123456797
4567890123456799
(6 rows)
-- corner case
SELECT (-1::int8<<63)::text;
text
----------------------
-9223372036854775808
(1 row)
SELECT ((-1::int8<<63)+1)::text;
text
----------------------
-9223372036854775807
(1 row)
-- check sane handling of INT64_MIN overflow cases
SELECT (-9223372036854775808)::int8 * (-1)::int8;
ERROR: bigint out of range
SELECT (-9223372036854775808)::int8 / (-1)::int8;
ERROR: bigint out of range
SELECT (-9223372036854775808)::int8 % (-1)::int8;
?column?
----------
0
(1 row)
SELECT (-9223372036854775808)::int8 * (-1)::int4;
ERROR: bigint out of range
SELECT (-9223372036854775808)::int8 / (-1)::int4;
ERROR: bigint out of range
SELECT (-9223372036854775808)::int8 % (-1)::int4;
?column?
----------
0
(1 row)
SELECT (-9223372036854775808)::int8 * (-1)::int2;
ERROR: bigint out of range
SELECT (-9223372036854775808)::int8 / (-1)::int2;
ERROR: bigint out of range
SELECT (-9223372036854775808)::int8 % (-1)::int2;
?column?
----------
0
(1 row)
-- check rounding when casting from float
SELECT x, x::int8 AS int8_value
FROM (VALUES (-2.5::float8),
(-1.5::float8),
(-0.5::float8),
(0.0::float8),
(0.5::float8),
(1.5::float8),
(2.5::float8)) t(x);
x | int8_value
------+------------
-2.5 | -2
-1.5 | -2
-0.5 | 0
0 | 0
0.5 | 0
1.5 | 2
2.5 | 2
(7 rows)
-- check rounding when casting from numeric
SELECT x, x::int8 AS int8_value
FROM (VALUES (-2.5::numeric),
(-1.5::numeric),
(-0.5::numeric),
(0.0::numeric),
(0.5::numeric),
(1.5::numeric),
(2.5::numeric)) t(x);
x | int8_value
------+------------
-2.5 | -3
-1.5 | -2
-0.5 | -1
0.0 | 0
0.5 | 1
1.5 | 2
2.5 | 3
(7 rows)

View File

@ -1,17 +1,5 @@
float4:out:i.86-pc-mingw32=float4-exp-three-digits.out
float4:out:x86_64-w64-mingw32=float4-exp-three-digits.out
float4:out:i.86-w64-mingw32=float4-exp-three-digits.out
float4:out:i.86-pc-win32vc=float4-exp-three-digits.out
float8:out:i.86-.*-freebsd=float8-small-is-zero.out
float8:out:i.86-.*-openbsd=float8-small-is-zero.out
float8:out:i.86-.*-netbsd=float8-small-is-zero.out
float8:out:m68k-.*-netbsd=float8-small-is-zero.out
float8:out:i.86-pc-mingw32=float8-exp-three-digits-win32.out
float8:out:x86_64-w64-mingw32=float8-exp-three-digits-win32.out
float8:out:i.86-w64-mingw32=float8-exp-three-digits-win32.out
float8:out:i.86-pc-win32vc=float8-exp-three-digits-win32.out
float8:out:i.86-pc-cygwin=float8-small-is-zero.out
int8:out:i.86-pc-mingw32=int8-exp-three-digits.out
int8:out:x86_64-w64-mingw32=int8-exp-three-digits.out
int8:out:i.86-w64-mingw32=int8-exp-three-digits.out
int8:out:i.86-pc-win32vc=int8-exp-three-digits.out