*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/float.c,v 1.97 2004/03/04 21:47:18 neilc Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/float.c,v 1.98 2004/03/11 02:11:13 neilc Exp $
*
*-------------------------------------------------------------------------
*/
errno = 0;
val = strtod(num, &endptr);
- if (*endptr != '\0')
+
+ if (errno == ERANGE)
+ ereport(ERROR,
+ (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
+ errmsg("\"%s\" is out of range for type real", num)));
+
+ if (num == endptr)
{
/*
- * XXX we should accept "Infinity" and "-Infinity" too, but what
- * are the correct values to assign? HUGE_VAL will provoke an
- * error from CheckFloat4Val.
+ * We didn't find anything that looks like a float in the input
+ *
+ * In releases prior to 7.5, we accepted an empty string as
+ * valid input (yielding a float8 of 0). In 7.5, we accept
+ * empty strings, but emit a warning noting that the feature
+ * is deprecated. In 7.6+, the warning should be replaced by
+ * an error.
+ *
+ * XXX we should accept "Infinity" and "-Infinity" too, but
+ * what are the correct values to assign? HUGE_VAL will
+ * provoke an error from CheckFloat4Val.
*/
- if (strcasecmp(num, "NaN") == 0)
+ if (*num == '\0')
+ {
+ ereport(WARNING,
+ (errcode(ERRCODE_WARNING_DEPRECATED_FEATURE),
+ errmsg("deprecated input syntax for type real: \"\""),
+ errdetail("This input will be rejected in "
+ "a future release of PostgreSQL.")));
+ Assert(val == 0.0);
+ }
+ else if (strcasecmp(num, "NaN") == 0)
val = NAN;
else
ereport(ERROR,
errmsg("invalid input syntax for type real: \"%s\"",
num)));
}
- else
- {
- if (errno == ERANGE)
- ereport(ERROR,
- (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
- errmsg("\"%s\" is out of range for type real", num)));
- }
- /*
- * In releases prior to 7.5, we accepted an empty string as valid
- * input (yielding a float4 of 0). In 7.5, we accept empty
- * strings, but emit a warning noting that the feature is
- * deprecated. In 7.6+, the warning should be replaced by an error.
- */
- if (num == endptr)
- ereport(WARNING,
- (errcode(ERRCODE_WARNING_DEPRECATED_FEATURE),
- errmsg("deprecated input syntax for type real: \"\""),
- errdetail("This input will be rejected in "
- "a future release of PostgreSQL.")));
+ /* skip trailing whitespace */
+ while (*endptr != '\0' && isspace(*endptr))
+ endptr++;
+
+ /* if there is any junk left at the end of the string, bail out */
+ if (*endptr != '\0')
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
+ errmsg("invalid input syntax for type real: \"%s\"",
+ num)));
/*
* if we get here, we have a legal double, still need to check to see
errno = 0;
val = strtod(num, &endptr);
- if (*endptr != '\0')
+
+ if (errno == ERANGE)
+ ereport(ERROR,
+ (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
+ errmsg("\"%s\" is out of range for type double precision", num)));
+
+ if (num == endptr)
{
- if (strcasecmp(num, "NaN") == 0)
+ /*
+ * We didn't find anything that looks like a float in the input
+ *
+ * In releases prior to 7.5, we accepted an empty string as
+ * valid input (yielding a float8 of 0). In 7.5, we accept
+ * empty strings, but emit a warning noting that the feature
+ * is deprecated. In 7.6+, the warning should be replaced by
+ * an error.
+ */
+ if (*num == '\0')
+ {
+ ereport(WARNING,
+ (errcode(ERRCODE_WARNING_DEPRECATED_FEATURE),
+ errmsg("deprecated input syntax for type double precision: \"\""),
+ errdetail("This input will be rejected in "
+ "a future release of PostgreSQL.")));
+ Assert(val == 0.0);
+ }
+ else if (strcasecmp(num, "NaN") == 0)
val = NAN;
else if (strcasecmp(num, "Infinity") == 0)
val = HUGE_VAL;
errmsg("invalid input syntax for type double precision: \"%s\"",
num)));
}
- else
- {
- if (errno == ERANGE)
- ereport(ERROR,
- (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
- errmsg("\"%s\" is out of range for type double precision", num)));
- }
- /*
- * In releases prior to 7.5, we accepted an empty string as valid
- * input (yielding a float8 of 0). In 7.5, we accept empty
- * strings, but emit a warning noting that the feature is
- * deprecated. In 7.6+, the warning should be replaced by an error.
- */
- if (num == endptr)
- ereport(WARNING,
- (errcode(ERRCODE_WARNING_DEPRECATED_FEATURE),
- errmsg("deprecated input syntax for type double precision: \"\""),
- errdetail("This input will be rejected in "
- "a future release of PostgreSQL.")));
+ /* skip trailing whitespace */
+ while (*endptr != '\0' && isspace(*endptr))
+ endptr++;
+
+ /* if there is any junk left at the end of the string, bail out */
+ if (*endptr != '\0')
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
+ errmsg("invalid input syntax for type double precision: \"%s\"",
+ num)));
CheckFloat8Val(val);
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/int8.c,v 1.51 2004/02/03 08:29:56 joe Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/int8.c,v 1.52 2004/03/11 02:11:13 neilc Exp $
*
*-------------------------------------------------------------------------
*/
tmp = newtmp;
}
- /* trailing junk? */
- if (*ptr)
+ /* allow trailing whitespace, but not other trailing chars */
+ while (*ptr != '\0' && isspace(*ptr))
+ ptr++;
+
+ if (*ptr != '\0')
{
if (errorOK)
return false;
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/numutils.c,v 1.61 2004/02/18 00:01:33 neilc Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/numutils.c,v 1.62 2004/03/11 02:11:13 neilc Exp $
*
*-------------------------------------------------------------------------
*/
#include <errno.h>
#include <math.h>
#include <limits.h>
+#include <ctype.h>
#include "utils/builtins.h"
/*
* pg_atoi: convert string to integer
*
- * size is the sizeof() the desired integral result (1, 2, or 4 bytes).
+ * 'size' is the sizeof() the desired integral result (1, 2, or 4 bytes).
*
- * c, if not 0, is the terminator character that may appear after the
- * integer. If 0, the string must end after the integer.
+ * allows any number of leading or trailing whitespace characters.
+ *
+ * 'c' is the character that terminates the input string (after any
+ * number of whitespace characters).
*
* Unlike plain atoi(), this will throw ereport() upon bad input format or
* overflow.
pg_atoi(char *s, int size, int c)
{
long l;
- char *badp = NULL;
+ char *badp;
/*
* Some versions of strtol treat the empty string as an error, but
errno = 0;
l = strtol(s, &badp, 10);
- /*
- * strtol() normally only sets ERANGE. On some systems it also may
- * set EINVAL, which simply means it couldn't parse the input string.
- * This is handled by the second "if" consistent across platforms.
- */
- if (errno && errno != ERANGE && errno != EINVAL)
+ /* We made no progress parsing the string, so bail out */
+ if (s == badp)
ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for integer: \"%s\"",
s)));
- if (badp && *badp && *badp != c)
+
+ /*
+ * Skip any trailing whitespace; if anything but whitespace
+ * remains before the terminating character, bail out
+ */
+ while (*badp != c && isspace(*badp))
+ badp++;
+
+ if (*badp != c)
ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for integer: \"%s\"",
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/oid.c,v 1.55 2004/03/04 21:47:18 neilc Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/oid.c,v 1.56 2004/03/11 02:11:13 neilc Exp $
*
*-------------------------------------------------------------------------
*/
char *endptr;
Oid result;
+ /*
+ * In releases prior to 7.5, we accepted an empty string as valid
+ * input (yielding an OID of 0). In 7.5, we accept empty strings,
+ * but emit a warning noting that the feature is deprecated. In
+ * 7.6+, the warning should be replaced by an error.
+ */
+ if (*s == '\0')
+ ereport(WARNING,
+ (errcode(ERRCODE_WARNING_DEPRECATED_FEATURE),
+ errmsg("deprecated input syntax for type oid: \"\""),
+ errdetail("This input will be rejected in "
+ "a future release of PostgreSQL.")));
+
errno = 0;
cvt = strtoul(s, &endptr, 10);
errmsg("invalid input syntax for type oid: \"%s\"",
s)));
- /*
- * In releases prior to 7.5, we accepted an empty string as valid
- * input (yielding an OID of 0). In 7.5, we accept empty strings,
- * but emit a warning noting that the feature is deprecated. In
- * 7.6+, the warning should be replaced by an error.
- */
- if (*s == '\0')
- ereport(WARNING,
- (errcode(ERRCODE_WARNING_DEPRECATED_FEATURE),
- errmsg("deprecated input syntax for type oid: \"\""),
- errdetail("This input will be rejected in "
- "a future release of PostgreSQL.")));
-
- if (endptr == s && *s)
+ if (endptr == s && *s != '\0')
ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for type oid: \"%s\"",
-- 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
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
------+-------------
-- 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
------+----------------------
-- 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
------+--------
-- 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
------+-------------
| 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
-------+---------
-- 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
------------------+-------------------
-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');
| -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)
+
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
-----+------------
| 987
| 4294966256
| 99999999
-(5 rows)
+ | 5
+ | 10
+ | 15
+(8 rows)
SELECT '' AS one, o.* FROM OID_TBL o WHERE o.f1 = 1234;
one | f1
| 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
num_exp_power_10_ln
num_exp_sqrt
num_exp_sub
+ num_input_test
num_result
onek
onek2
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');
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.*;
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.*;
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.*;
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.*;
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;
--
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;
-- ******************************
-- 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));
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;
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.*;