mirror of
https://github.com/postgres/postgres.git
synced 2025-12-10 14:22:35 +03:00
Revise int2/int4/int8/float4/float8 input routines to allow for
any amount of leading or trailing whitespace (where "whitespace" is defined by isspace()). This is for SQL conformance, as well as consistency with other numeric types (e.g. oid, numeric). Also refactor pg_atoi() to avoid looking at errno where not necessary, and add a bunch of regression tests for the input to these types.
This commit is contained in:
@@ -2,9 +2,9 @@
|
||||
-- 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 (' 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
|
||||
@@ -16,6 +16,43 @@ INSERT INTO FLOAT4_TBL(f1) VALUES ('10e-40');
|
||||
ERROR: type "real" value out of range: underflow
|
||||
INSERT INTO FLOAT4_TBL(f1) VALUES ('-10e-40');
|
||||
ERROR: type "real" value out of range: underflow
|
||||
-- bad input
|
||||
INSERT INTO FLOAT4_TBL(f1) VALUES (' ');
|
||||
ERROR: invalid input syntax for type real: " "
|
||||
INSERT INTO FLOAT4_TBL(f1) VALUES ('xyz');
|
||||
ERROR: invalid input syntax for type real: "xyz"
|
||||
INSERT INTO FLOAT4_TBL(f1) VALUES ('5.0.0');
|
||||
ERROR: invalid input syntax for type real: "5.0.0"
|
||||
INSERT INTO FLOAT4_TBL(f1) VALUES ('5 . 0');
|
||||
ERROR: invalid input syntax for type real: "5 . 0"
|
||||
INSERT INTO FLOAT4_TBL(f1) VALUES ('5. 0');
|
||||
ERROR: invalid input syntax for type real: "5. 0"
|
||||
INSERT INTO FLOAT4_TBL(f1) VALUES (' - 3.0');
|
||||
ERROR: invalid input syntax for type real: " - 3.0"
|
||||
INSERT INTO FLOAT4_TBL(f1) VALUES ('123 5');
|
||||
ERROR: invalid input syntax for type real: "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)
|
||||
|
||||
-- bad special inputs
|
||||
SELECT 'N A N'::float4;
|
||||
ERROR: invalid input syntax for type real: "N A N"
|
||||
SELECT '' AS five, FLOAT4_TBL.*;
|
||||
five | f1
|
||||
------+-------------
|
||||
|
||||
@@ -2,11 +2,57 @@
|
||||
-- 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 (' 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
|
||||
INSERT INTO FLOAT8_TBL(f1) VALUES ('10e400');
|
||||
ERROR: "10e400" is out of range for type double precision
|
||||
INSERT INTO FLOAT8_TBL(f1) VALUES ('-10e400');
|
||||
ERROR: "-10e400" is out of range for type double precision
|
||||
INSERT INTO FLOAT8_TBL(f1) VALUES ('10e-400');
|
||||
ERROR: "10e-400" is out of range for type double precision
|
||||
INSERT INTO FLOAT8_TBL(f1) VALUES ('-10e-400');
|
||||
ERROR: "-10e-400" is out of range for type double precision
|
||||
-- bad input
|
||||
INSERT INTO FLOAT8_TBL(f1) VALUES (' ');
|
||||
ERROR: invalid input syntax for type double precision: " "
|
||||
INSERT INTO FLOAT8_TBL(f1) VALUES ('xyz');
|
||||
ERROR: invalid input syntax for type double precision: "xyz"
|
||||
INSERT INTO FLOAT8_TBL(f1) VALUES ('5.0.0');
|
||||
ERROR: invalid input syntax for type double precision: "5.0.0"
|
||||
INSERT INTO FLOAT8_TBL(f1) VALUES ('5 . 0');
|
||||
ERROR: invalid input syntax for type double precision: "5 . 0"
|
||||
INSERT INTO FLOAT8_TBL(f1) VALUES ('5. 0');
|
||||
ERROR: invalid input syntax for type double precision: "5. 0"
|
||||
INSERT INTO FLOAT8_TBL(f1) VALUES (' - 3');
|
||||
ERROR: invalid input syntax for type double precision: " - 3"
|
||||
INSERT INTO FLOAT8_TBL(f1) VALUES ('123 5');
|
||||
ERROR: invalid input syntax for type double precision: "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)
|
||||
|
||||
-- bad special inputs
|
||||
SELECT 'N A N'::float8;
|
||||
ERROR: invalid input syntax for type double precision: "N A N"
|
||||
SELECT '' AS five, FLOAT8_TBL.*;
|
||||
five | f1
|
||||
------+----------------------
|
||||
|
||||
@@ -4,19 +4,29 @@
|
||||
-- Some of these answers are consequently numerically incorrect.
|
||||
--
|
||||
CREATE TABLE INT2_TBL(f1 int2);
|
||||
INSERT INTO INT2_TBL(f1) VALUES ('0');
|
||||
INSERT INTO INT2_TBL(f1) VALUES ('1234');
|
||||
INSERT INTO INT2_TBL(f1) VALUES ('-1234');
|
||||
INSERT INTO INT2_TBL(f1) VALUES ('0 ');
|
||||
INSERT INTO INT2_TBL(f1) VALUES (' 1234 ');
|
||||
INSERT INTO INT2_TBL(f1) VALUES (' -1234');
|
||||
INSERT INTO INT2_TBL(f1) VALUES ('34.5');
|
||||
ERROR: invalid input syntax for integer: "34.5"
|
||||
-- largest and smallest values
|
||||
-- largest and smallest values
|
||||
INSERT INTO INT2_TBL(f1) VALUES ('32767');
|
||||
INSERT INTO INT2_TBL(f1) VALUES ('-32767');
|
||||
-- bad input values -- should give warnings
|
||||
-- bad input values -- should give errors
|
||||
INSERT INTO INT2_TBL(f1) VALUES ('100000');
|
||||
ERROR: value "100000" is out of range for type shortint
|
||||
INSERT INTO INT2_TBL(f1) VALUES ('asdf');
|
||||
ERROR: invalid input syntax for integer: "asdf"
|
||||
INSERT INTO INT2_TBL(f1) VALUES (' ');
|
||||
ERROR: invalid input syntax for integer: " "
|
||||
INSERT INTO INT2_TBL(f1) VALUES ('- 1234');
|
||||
ERROR: invalid input syntax for integer: "- 1234"
|
||||
INSERT INTO INT2_TBL(f1) VALUES ('4 444');
|
||||
ERROR: invalid input syntax for integer: "4 444"
|
||||
INSERT INTO INT2_TBL(f1) VALUES ('123 dt');
|
||||
ERROR: invalid input syntax for integer: "123 dt"
|
||||
INSERT INTO INT2_TBL(f1) VALUES ('');
|
||||
ERROR: invalid input syntax for integer: ""
|
||||
SELECT '' AS five, INT2_TBL.*;
|
||||
five | f1
|
||||
------+--------
|
||||
|
||||
@@ -4,19 +4,29 @@
|
||||
-- Some of these answers are consequently numerically incorrect.
|
||||
--
|
||||
CREATE TABLE INT4_TBL(f1 int4);
|
||||
INSERT INTO INT4_TBL(f1) VALUES ('0');
|
||||
INSERT INTO INT4_TBL(f1) VALUES ('123456');
|
||||
INSERT INTO INT4_TBL(f1) VALUES ('-123456');
|
||||
INSERT INTO INT4_TBL(f1) VALUES (' 0 ');
|
||||
INSERT INTO INT4_TBL(f1) VALUES ('123456 ');
|
||||
INSERT INTO INT4_TBL(f1) VALUES (' -123456');
|
||||
INSERT INTO INT4_TBL(f1) VALUES ('34.5');
|
||||
ERROR: invalid input syntax for integer: "34.5"
|
||||
-- largest and smallest values
|
||||
-- largest and smallest values
|
||||
INSERT INTO INT4_TBL(f1) VALUES ('2147483647');
|
||||
INSERT INTO INT4_TBL(f1) VALUES ('-2147483647');
|
||||
-- bad input values -- should give warnings
|
||||
-- bad input values -- should give errors
|
||||
INSERT INTO INT4_TBL(f1) VALUES ('1000000000000');
|
||||
ERROR: value "1000000000000" is out of range for type integer
|
||||
INSERT INTO INT4_TBL(f1) VALUES ('asdf');
|
||||
ERROR: invalid input syntax for integer: "asdf"
|
||||
INSERT INTO INT4_TBL(f1) VALUES (' ');
|
||||
ERROR: invalid input syntax for integer: " "
|
||||
INSERT INTO INT4_TBL(f1) VALUES (' asdf ');
|
||||
ERROR: invalid input syntax for integer: " asdf "
|
||||
INSERT INTO INT4_TBL(f1) VALUES ('- 1234');
|
||||
ERROR: invalid input syntax for integer: "- 1234"
|
||||
INSERT INTO INT4_TBL(f1) VALUES ('123 5');
|
||||
ERROR: invalid input syntax for integer: "123 5"
|
||||
INSERT INTO INT4_TBL(f1) VALUES ('');
|
||||
ERROR: invalid input syntax for integer: ""
|
||||
SELECT '' AS five, INT4_TBL.*;
|
||||
five | f1
|
||||
------+-------------
|
||||
@@ -117,14 +127,14 @@ SELECT '' AS three, i.* FROM INT4_TBL i WHERE i.f1 >= int4 '0';
|
||||
| 2147483647
|
||||
(3 rows)
|
||||
|
||||
-- positive odds
|
||||
-- positive odds
|
||||
SELECT '' AS one, i.* FROM INT4_TBL i WHERE (i.f1 % int2 '2') = int2 '1';
|
||||
one | f1
|
||||
-----+------------
|
||||
| 2147483647
|
||||
(1 row)
|
||||
|
||||
-- any evens
|
||||
-- any evens
|
||||
SELECT '' AS three, i.* FROM INT4_TBL i WHERE (i.f1 % int4 '2') = int2 '0';
|
||||
three | f1
|
||||
-------+---------
|
||||
|
||||
@@ -3,11 +3,26 @@
|
||||
-- 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(' 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: " "
|
||||
INSERT INTO INT8_TBL(q1) VALUES ('xxx');
|
||||
ERROR: invalid input syntax for type bigint: "xxx"
|
||||
INSERT INTO INT8_TBL(q1) VALUES ('3908203590239580293850293850329485');
|
||||
ERROR: integer out of range
|
||||
INSERT INTO INT8_TBL(q1) VALUES ('-1204982019841029840928340329840934');
|
||||
ERROR: integer out of range
|
||||
INSERT INTO INT8_TBL(q1) VALUES ('- 123');
|
||||
ERROR: invalid input syntax for type bigint: "- 123"
|
||||
INSERT INTO INT8_TBL(q1) VALUES (' 345 5');
|
||||
ERROR: invalid input syntax for type bigint: " 345 5"
|
||||
INSERT INTO INT8_TBL(q1) VALUES ('');
|
||||
ERROR: invalid input syntax for type bigint: ""
|
||||
SELECT * FROM INT8_TBL;
|
||||
q1 | q2
|
||||
------------------+-------------------
|
||||
|
||||
@@ -670,6 +670,18 @@ SELECT AVG(val) FROM num_data;
|
||||
-13430913.592242320700
|
||||
(1 row)
|
||||
|
||||
SELECT STDDEV(val) FROM num_data;
|
||||
stddev
|
||||
-------------------------------
|
||||
27791203.28758835329805617386
|
||||
(1 row)
|
||||
|
||||
SELECT VARIANCE(val) FROM num_data;
|
||||
variance
|
||||
--------------------------------------
|
||||
772350980172061.69659105821915863601
|
||||
(1 row)
|
||||
|
||||
-- Check for appropriate rounding and overflow
|
||||
CREATE TABLE fract_only (id int, val numeric(4,4));
|
||||
INSERT INTO fract_only VALUES (1, '0.0');
|
||||
@@ -1112,3 +1124,44 @@ SELECT '' AS to_number_13, to_number(' . 0 1 -', ' 9 9 . 9 9 S');
|
||||
| -0.01
|
||||
(1 row)
|
||||
|
||||
--
|
||||
-- Input syntax
|
||||
--
|
||||
CREATE TABLE num_input_test (n1 numeric);
|
||||
-- good inputs
|
||||
INSERT INTO num_input_test(n1) VALUES (' 123');
|
||||
INSERT INTO num_input_test(n1) VALUES (' 3245874 ');
|
||||
INSERT INTO num_input_test(n1) VALUES (' -93853');
|
||||
INSERT INTO num_input_test(n1) VALUES ('555.50');
|
||||
INSERT INTO num_input_test(n1) VALUES ('-555.50');
|
||||
INSERT INTO num_input_test(n1) VALUES ('NaN ');
|
||||
ERROR: invalid input syntax for type numeric: "NaN "
|
||||
INSERT INTO num_input_test(n1) VALUES (' nan');
|
||||
ERROR: invalid input syntax for type numeric: " nan"
|
||||
-- bad inputs
|
||||
INSERT INTO num_input_test(n1) VALUES (' ');
|
||||
ERROR: invalid input syntax for type numeric: " "
|
||||
INSERT INTO num_input_test(n1) VALUES (' 1234 %');
|
||||
ERROR: invalid input syntax for type numeric: " 1234 %"
|
||||
INSERT INTO num_input_test(n1) VALUES ('xyz');
|
||||
ERROR: invalid input syntax for type numeric: "xyz"
|
||||
INSERT INTO num_input_test(n1) VALUES ('- 1234');
|
||||
ERROR: invalid input syntax for type numeric: "- 1234"
|
||||
INSERT INTO num_input_test(n1) VALUES ('5 . 0');
|
||||
ERROR: invalid input syntax for type numeric: "5 . 0"
|
||||
INSERT INTO num_input_test(n1) VALUES ('5. 0 ');
|
||||
ERROR: invalid input syntax for type numeric: "5. 0 "
|
||||
INSERT INTO num_input_test(n1) VALUES ('');
|
||||
ERROR: invalid input syntax for type numeric: ""
|
||||
INSERT INTO num_input_test(n1) VALUES (' N aN ');
|
||||
ERROR: invalid input syntax for type numeric: " N aN "
|
||||
SELECT * FROM num_input_test;
|
||||
n1
|
||||
---------
|
||||
123
|
||||
3245874
|
||||
-93853
|
||||
555.50
|
||||
-555.50
|
||||
(5 rows)
|
||||
|
||||
|
||||
@@ -7,11 +7,29 @@ INSERT INTO OID_TBL(f1) VALUES ('1235');
|
||||
INSERT INTO OID_TBL(f1) VALUES ('987');
|
||||
INSERT INTO OID_TBL(f1) VALUES ('-1040');
|
||||
INSERT INTO OID_TBL(f1) VALUES ('99999999');
|
||||
INSERT INTO OID_TBL(f1) VALUES ('5 ');
|
||||
INSERT INTO OID_TBL(f1) VALUES (' 10 ');
|
||||
-- leading/trailing hard tab is also allowed
|
||||
INSERT INTO OID_TBL(f1) VALUES (' 15 ');
|
||||
-- bad inputs
|
||||
INSERT INTO OID_TBL(f1) VALUES ('asdfasd');
|
||||
ERROR: invalid input syntax for type oid: "asdfasd"
|
||||
INSERT INTO OID_TBL(f1) VALUES ('99asdfasd');
|
||||
ERROR: invalid input syntax for type oid: "99asdfasd"
|
||||
INSERT INTO OID_TBL(f1) VALUES ('5 d');
|
||||
ERROR: invalid input syntax for type oid: "5 d"
|
||||
INSERT INTO OID_TBL(f1) VALUES (' 5d');
|
||||
ERROR: invalid input syntax for type oid: " 5d"
|
||||
INSERT INTO OID_TBL(f1) VALUES ('5 5');
|
||||
ERROR: invalid input syntax for type oid: "5 5"
|
||||
INSERT INTO OID_TBL(f1) VALUES (' ');
|
||||
ERROR: invalid input syntax for type oid: " "
|
||||
INSERT INTO OID_TBL(f1) VALUES (' - 500');
|
||||
ERROR: invalid input syntax for type oid: " - 500"
|
||||
INSERT INTO OID_TBL(f1) VALUES ('32958209582039852935');
|
||||
ERROR: value "32958209582039852935" is out of range for type oid
|
||||
INSERT INTO OID_TBL(f1) VALUES ('-23582358720398502385');
|
||||
ERROR: value "-23582358720398502385" is out of range for type oid
|
||||
SELECT '' AS six, OID_TBL.*;
|
||||
six | f1
|
||||
-----+------------
|
||||
@@ -20,7 +38,10 @@ SELECT '' AS six, OID_TBL.*;
|
||||
| 987
|
||||
| 4294966256
|
||||
| 99999999
|
||||
(5 rows)
|
||||
| 5
|
||||
| 10
|
||||
| 15
|
||||
(8 rows)
|
||||
|
||||
SELECT '' AS one, o.* FROM OID_TBL o WHERE o.f1 = 1234;
|
||||
one | f1
|
||||
@@ -35,20 +56,29 @@ SELECT '' AS five, o.* FROM OID_TBL o WHERE o.f1 <> '1234';
|
||||
| 987
|
||||
| 4294966256
|
||||
| 99999999
|
||||
(4 rows)
|
||||
| 5
|
||||
| 10
|
||||
| 15
|
||||
(7 rows)
|
||||
|
||||
SELECT '' AS three, o.* FROM OID_TBL o WHERE o.f1 <= '1234';
|
||||
three | f1
|
||||
-------+------
|
||||
| 1234
|
||||
| 987
|
||||
(2 rows)
|
||||
| 5
|
||||
| 10
|
||||
| 15
|
||||
(5 rows)
|
||||
|
||||
SELECT '' AS two, o.* FROM OID_TBL o WHERE o.f1 < '1234';
|
||||
two | f1
|
||||
-----+-----
|
||||
| 987
|
||||
(1 row)
|
||||
| 5
|
||||
| 10
|
||||
| 15
|
||||
(4 rows)
|
||||
|
||||
SELECT '' AS four, o.* FROM OID_TBL o WHERE o.f1 >= '1234';
|
||||
four | f1
|
||||
|
||||
@@ -631,6 +631,7 @@ SELECT user_relns() AS user_relns
|
||||
num_exp_power_10_ln
|
||||
num_exp_sqrt
|
||||
num_exp_sub
|
||||
num_input_test
|
||||
num_result
|
||||
onek
|
||||
onek2
|
||||
@@ -660,7 +661,7 @@ SELECT user_relns() AS user_relns
|
||||
toyemp
|
||||
varchar_tbl
|
||||
xacttest
|
||||
(96 rows)
|
||||
(97 rows)
|
||||
|
||||
--SELECT name(equipment(hobby_construct(text 'skywalking', text 'mer'))) AS equip_name;
|
||||
SELECT hobbies_by_name('basketball');
|
||||
|
||||
@@ -4,25 +4,33 @@
|
||||
|
||||
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 (' 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 ('10e40');
|
||||
|
||||
INSERT INTO FLOAT4_TBL(f1) VALUES ('-10e40');
|
||||
|
||||
INSERT INTO FLOAT4_TBL(f1) VALUES ('10e-40');
|
||||
|
||||
INSERT INTO FLOAT4_TBL(f1) VALUES ('-10e-40');
|
||||
|
||||
-- bad input
|
||||
INSERT INTO FLOAT4_TBL(f1) VALUES (' ');
|
||||
INSERT INTO FLOAT4_TBL(f1) VALUES ('xyz');
|
||||
INSERT INTO FLOAT4_TBL(f1) VALUES ('5.0.0');
|
||||
INSERT INTO FLOAT4_TBL(f1) VALUES ('5 . 0');
|
||||
INSERT INTO FLOAT4_TBL(f1) VALUES ('5. 0');
|
||||
INSERT INTO FLOAT4_TBL(f1) VALUES (' - 3.0');
|
||||
INSERT INTO FLOAT4_TBL(f1) VALUES ('123 5');
|
||||
|
||||
-- special inputs
|
||||
SELECT 'NaN'::float4;
|
||||
SELECT 'nan'::float4;
|
||||
SELECT ' NAN '::float4;
|
||||
-- bad special inputs
|
||||
SELECT 'N A N'::float4;
|
||||
|
||||
SELECT '' AS five, FLOAT4_TBL.*;
|
||||
|
||||
|
||||
@@ -4,16 +4,33 @@
|
||||
|
||||
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 (' 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
|
||||
INSERT INTO FLOAT8_TBL(f1) VALUES ('10e400');
|
||||
INSERT INTO FLOAT8_TBL(f1) VALUES ('-10e400');
|
||||
INSERT INTO FLOAT8_TBL(f1) VALUES ('10e-400');
|
||||
INSERT INTO FLOAT8_TBL(f1) VALUES ('-10e-400');
|
||||
|
||||
-- bad input
|
||||
INSERT INTO FLOAT8_TBL(f1) VALUES (' ');
|
||||
INSERT INTO FLOAT8_TBL(f1) VALUES ('xyz');
|
||||
INSERT INTO FLOAT8_TBL(f1) VALUES ('5.0.0');
|
||||
INSERT INTO FLOAT8_TBL(f1) VALUES ('5 . 0');
|
||||
INSERT INTO FLOAT8_TBL(f1) VALUES ('5. 0');
|
||||
INSERT INTO FLOAT8_TBL(f1) VALUES (' - 3');
|
||||
INSERT INTO FLOAT8_TBL(f1) VALUES ('123 5');
|
||||
|
||||
-- special inputs
|
||||
SELECT 'NaN'::float8;
|
||||
SELECT 'nan'::float8;
|
||||
SELECT ' NAN '::float8;
|
||||
-- bad special inputs
|
||||
SELECT 'N A N'::float8;
|
||||
|
||||
SELECT '' AS five, FLOAT8_TBL.*;
|
||||
|
||||
|
||||
@@ -6,23 +6,27 @@
|
||||
|
||||
CREATE TABLE INT2_TBL(f1 int2);
|
||||
|
||||
INSERT INTO INT2_TBL(f1) VALUES ('0');
|
||||
INSERT INTO INT2_TBL(f1) VALUES ('0 ');
|
||||
|
||||
INSERT INTO INT2_TBL(f1) VALUES ('1234');
|
||||
INSERT INTO INT2_TBL(f1) VALUES (' 1234 ');
|
||||
|
||||
INSERT INTO INT2_TBL(f1) VALUES ('-1234');
|
||||
INSERT INTO INT2_TBL(f1) VALUES (' -1234');
|
||||
|
||||
INSERT INTO INT2_TBL(f1) VALUES ('34.5');
|
||||
|
||||
-- largest and smallest values
|
||||
-- largest and smallest values
|
||||
INSERT INTO INT2_TBL(f1) VALUES ('32767');
|
||||
|
||||
INSERT INTO INT2_TBL(f1) VALUES ('-32767');
|
||||
|
||||
-- bad input values -- should give warnings
|
||||
-- bad input values -- should give errors
|
||||
INSERT INTO INT2_TBL(f1) VALUES ('100000');
|
||||
|
||||
INSERT INTO INT2_TBL(f1) VALUES ('asdf');
|
||||
INSERT INTO INT2_TBL(f1) VALUES (' ');
|
||||
INSERT INTO INT2_TBL(f1) VALUES ('- 1234');
|
||||
INSERT INTO INT2_TBL(f1) VALUES ('4 444');
|
||||
INSERT INTO INT2_TBL(f1) VALUES ('123 dt');
|
||||
INSERT INTO INT2_TBL(f1) VALUES ('');
|
||||
|
||||
|
||||
SELECT '' AS five, INT2_TBL.*;
|
||||
|
||||
@@ -6,23 +6,27 @@
|
||||
|
||||
CREATE TABLE INT4_TBL(f1 int4);
|
||||
|
||||
INSERT INTO INT4_TBL(f1) VALUES ('0');
|
||||
INSERT INTO INT4_TBL(f1) VALUES (' 0 ');
|
||||
|
||||
INSERT INTO INT4_TBL(f1) VALUES ('123456');
|
||||
INSERT INTO INT4_TBL(f1) VALUES ('123456 ');
|
||||
|
||||
INSERT INTO INT4_TBL(f1) VALUES ('-123456');
|
||||
INSERT INTO INT4_TBL(f1) VALUES (' -123456');
|
||||
|
||||
INSERT INTO INT4_TBL(f1) VALUES ('34.5');
|
||||
|
||||
-- largest and smallest values
|
||||
-- largest and smallest values
|
||||
INSERT INTO INT4_TBL(f1) VALUES ('2147483647');
|
||||
|
||||
INSERT INTO INT4_TBL(f1) VALUES ('-2147483647');
|
||||
|
||||
-- bad input values -- should give warnings
|
||||
-- bad input values -- should give errors
|
||||
INSERT INTO INT4_TBL(f1) VALUES ('1000000000000');
|
||||
|
||||
INSERT INTO INT4_TBL(f1) VALUES ('asdf');
|
||||
INSERT INTO INT4_TBL(f1) VALUES (' ');
|
||||
INSERT INTO INT4_TBL(f1) VALUES (' asdf ');
|
||||
INSERT INTO INT4_TBL(f1) VALUES ('- 1234');
|
||||
INSERT INTO INT4_TBL(f1) VALUES ('123 5');
|
||||
INSERT INTO INT4_TBL(f1) VALUES ('');
|
||||
|
||||
|
||||
SELECT '' AS five, INT4_TBL.*;
|
||||
@@ -51,10 +55,10 @@ SELECT '' AS three, i.* FROM INT4_TBL i WHERE i.f1 >= int2 '0';
|
||||
|
||||
SELECT '' AS three, i.* FROM INT4_TBL i WHERE i.f1 >= int4 '0';
|
||||
|
||||
-- positive odds
|
||||
-- positive odds
|
||||
SELECT '' AS one, i.* FROM INT4_TBL i WHERE (i.f1 % int2 '2') = int2 '1';
|
||||
|
||||
-- any evens
|
||||
-- any evens
|
||||
SELECT '' AS three, i.* FROM INT4_TBL i WHERE (i.f1 % int4 '2') = int2 '0';
|
||||
|
||||
SELECT '' AS five, i.f1, i.f1 * int2 '2' AS x FROM INT4_TBL i;
|
||||
|
||||
@@ -4,12 +4,21 @@
|
||||
--
|
||||
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(' 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 (' ');
|
||||
INSERT INTO INT8_TBL(q1) VALUES ('xxx');
|
||||
INSERT INTO INT8_TBL(q1) VALUES ('3908203590239580293850293850329485');
|
||||
INSERT INTO INT8_TBL(q1) VALUES ('-1204982019841029840928340329840934');
|
||||
INSERT INTO INT8_TBL(q1) VALUES ('- 123');
|
||||
INSERT INTO INT8_TBL(q1) VALUES (' 345 5');
|
||||
INSERT INTO INT8_TBL(q1) VALUES ('');
|
||||
|
||||
SELECT * FROM INT8_TBL;
|
||||
|
||||
SELECT '' AS five, q1 AS plus, -q1 AS minus FROM INT8_TBL;
|
||||
|
||||
@@ -639,6 +639,8 @@ SELECT t1.id1, t1.result, t2.expected
|
||||
-- ******************************
|
||||
-- numeric AVG used to fail on some platforms
|
||||
SELECT AVG(val) FROM num_data;
|
||||
SELECT STDDEV(val) FROM num_data;
|
||||
SELECT VARIANCE(val) FROM num_data;
|
||||
|
||||
-- Check for appropriate rounding and overflow
|
||||
CREATE TABLE fract_only (id int, val numeric(4,4));
|
||||
@@ -701,3 +703,30 @@ SELECT '' AS to_number_10, to_number('0', '99.99');
|
||||
SELECT '' AS to_number_11, to_number('.-01', 'S99.99');
|
||||
SELECT '' AS to_number_12, to_number('.01-', '99.99S');
|
||||
SELECT '' AS to_number_13, to_number(' . 0 1 -', ' 9 9 . 9 9 S');
|
||||
|
||||
--
|
||||
-- Input syntax
|
||||
--
|
||||
|
||||
CREATE TABLE num_input_test (n1 numeric);
|
||||
|
||||
-- good inputs
|
||||
INSERT INTO num_input_test(n1) VALUES (' 123');
|
||||
INSERT INTO num_input_test(n1) VALUES (' 3245874 ');
|
||||
INSERT INTO num_input_test(n1) VALUES (' -93853');
|
||||
INSERT INTO num_input_test(n1) VALUES ('555.50');
|
||||
INSERT INTO num_input_test(n1) VALUES ('-555.50');
|
||||
INSERT INTO num_input_test(n1) VALUES ('NaN ');
|
||||
INSERT INTO num_input_test(n1) VALUES (' nan');
|
||||
|
||||
-- bad inputs
|
||||
INSERT INTO num_input_test(n1) VALUES (' ');
|
||||
INSERT INTO num_input_test(n1) VALUES (' 1234 %');
|
||||
INSERT INTO num_input_test(n1) VALUES ('xyz');
|
||||
INSERT INTO num_input_test(n1) VALUES ('- 1234');
|
||||
INSERT INTO num_input_test(n1) VALUES ('5 . 0');
|
||||
INSERT INTO num_input_test(n1) VALUES ('5. 0 ');
|
||||
INSERT INTO num_input_test(n1) VALUES ('');
|
||||
INSERT INTO num_input_test(n1) VALUES (' N aN ');
|
||||
|
||||
SELECT * FROM num_input_test;
|
||||
|
||||
@@ -5,19 +5,26 @@
|
||||
CREATE TABLE OID_TBL(f1 oid);
|
||||
|
||||
INSERT INTO OID_TBL(f1) VALUES ('1234');
|
||||
|
||||
INSERT INTO OID_TBL(f1) VALUES ('1235');
|
||||
|
||||
INSERT INTO OID_TBL(f1) VALUES ('987');
|
||||
|
||||
INSERT INTO OID_TBL(f1) VALUES ('-1040');
|
||||
|
||||
INSERT INTO OID_TBL(f1) VALUES ('99999999');
|
||||
INSERT INTO OID_TBL(f1) VALUES ('5 ');
|
||||
INSERT INTO OID_TBL(f1) VALUES (' 10 ');
|
||||
-- leading/trailing hard tab is also allowed
|
||||
INSERT INTO OID_TBL(f1) VALUES (' 15 ');
|
||||
|
||||
-- bad inputs
|
||||
|
||||
INSERT INTO OID_TBL(f1) VALUES ('asdfasd');
|
||||
INSERT INTO OID_TBL(f1) VALUES ('99asdfasd');
|
||||
INSERT INTO OID_TBL(f1) VALUES ('5 d');
|
||||
INSERT INTO OID_TBL(f1) VALUES (' 5d');
|
||||
INSERT INTO OID_TBL(f1) VALUES ('5 5');
|
||||
INSERT INTO OID_TBL(f1) VALUES (' ');
|
||||
INSERT INTO OID_TBL(f1) VALUES (' - 500');
|
||||
INSERT INTO OID_TBL(f1) VALUES ('32958209582039852935');
|
||||
INSERT INTO OID_TBL(f1) VALUES ('-23582358720398502385');
|
||||
|
||||
SELECT '' AS six, OID_TBL.*;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user