Adjust input routines for float4, float8 and oid to reject the empty string
as valid input (it was previously treated as 0). This input was deprecated in 8.0 (and a warning was emitted). Regression tests updated.
This commit is contained in:
parent
4db84f0880
commit
975e27377a
|
@ -8,7 +8,7 @@
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/utils/adt/float.c,v 1.112 2004/12/31 22:01:21 pgsql Exp $
|
* $PostgreSQL: pgsql/src/backend/utils/adt/float.c,v 1.113 2005/02/11 04:08:58 neilc Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
@ -267,21 +267,12 @@ float4in(PG_FUNCTION_ARGS)
|
||||||
/*
|
/*
|
||||||
* Check for an empty-string input to begin with, to avoid the
|
* Check for an empty-string input to begin with, to avoid the
|
||||||
* vagaries of strtod() on different platforms.
|
* vagaries of strtod() on different platforms.
|
||||||
*
|
|
||||||
* In releases prior to 8.0, we accepted an empty string as valid input
|
|
||||||
* (yielding a float4 of 0). In 8.0, we accept empty strings, but emit
|
|
||||||
* a warning noting that the feature is deprecated. In 8.1+, the
|
|
||||||
* warning should be replaced by an error.
|
|
||||||
*/
|
*/
|
||||||
if (*num == '\0')
|
if (*num == '\0')
|
||||||
{
|
ereport(ERROR,
|
||||||
ereport(WARNING,
|
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
|
||||||
(errcode(ERRCODE_WARNING_DEPRECATED_FEATURE),
|
errmsg("invalid input syntax for type real: \"%s\"",
|
||||||
errmsg("deprecated input syntax for type real: \"\""),
|
orig_num)));
|
||||||
errdetail("This input will be rejected in "
|
|
||||||
"a future release of PostgreSQL.")));
|
|
||||||
PG_RETURN_FLOAT4((float4) 0.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* skip leading whitespace */
|
/* skip leading whitespace */
|
||||||
while (*num != '\0' && isspace((unsigned char) *num))
|
while (*num != '\0' && isspace((unsigned char) *num))
|
||||||
|
@ -444,21 +435,12 @@ float8in(PG_FUNCTION_ARGS)
|
||||||
/*
|
/*
|
||||||
* Check for an empty-string input to begin with, to avoid the
|
* Check for an empty-string input to begin with, to avoid the
|
||||||
* vagaries of strtod() on different platforms.
|
* vagaries of strtod() on different platforms.
|
||||||
*
|
|
||||||
* In releases prior to 8.0, we accepted an empty string as valid input
|
|
||||||
* (yielding a float8 of 0). In 8.0, we accept empty strings, but emit
|
|
||||||
* a warning noting that the feature is deprecated. In 8.1+, the
|
|
||||||
* warning should be replaced by an error.
|
|
||||||
*/
|
*/
|
||||||
if (*num == '\0')
|
if (*num == '\0')
|
||||||
{
|
ereport(ERROR,
|
||||||
ereport(WARNING,
|
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
|
||||||
(errcode(ERRCODE_WARNING_DEPRECATED_FEATURE),
|
errmsg("invalid input syntax for type double precision: \"%s\"",
|
||||||
errmsg("deprecated input syntax for type double precision: \"\""),
|
orig_num)));
|
||||||
errdetail("This input will be rejected in "
|
|
||||||
"a future release of PostgreSQL.")));
|
|
||||||
PG_RETURN_FLOAT8(0.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* skip leading whitespace */
|
/* skip leading whitespace */
|
||||||
while (*num != '\0' && isspace((unsigned char) *num))
|
while (*num != '\0' && isspace((unsigned char) *num))
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/utils/adt/oid.c,v 1.60 2004/12/31 22:01:22 pgsql Exp $
|
* $PostgreSQL: pgsql/src/backend/utils/adt/oid.c,v 1.61 2005/02/11 04:08:58 neilc Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
@ -33,18 +33,11 @@ oidin_subr(const char *funcname, const char *s, char **endloc)
|
||||||
char *endptr;
|
char *endptr;
|
||||||
Oid result;
|
Oid result;
|
||||||
|
|
||||||
/*
|
|
||||||
* In releases prior to 8.0, we accepted an empty string as valid
|
|
||||||
* input (yielding an OID of 0). In 8.0, we accept empty strings, but
|
|
||||||
* emit a warning noting that the feature is deprecated. In 8.1+, the
|
|
||||||
* warning should be replaced by an error.
|
|
||||||
*/
|
|
||||||
if (*s == '\0')
|
if (*s == '\0')
|
||||||
ereport(WARNING,
|
ereport(ERROR,
|
||||||
(errcode(ERRCODE_WARNING_DEPRECATED_FEATURE),
|
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
|
||||||
errmsg("deprecated input syntax for type oid: \"\""),
|
errmsg("invalid input syntax for type oid: \"%s\"",
|
||||||
errdetail("This input will be rejected in "
|
s)));
|
||||||
"a future release of PostgreSQL.")));
|
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
cvt = strtoul(s, &endptr, 10);
|
cvt = strtoul(s, &endptr, 10);
|
||||||
|
|
|
@ -17,6 +17,8 @@ ERROR: type "real" value out of range: underflow
|
||||||
INSERT INTO FLOAT4_TBL(f1) VALUES ('-10e-40');
|
INSERT INTO FLOAT4_TBL(f1) VALUES ('-10e-40');
|
||||||
ERROR: type "real" value out of range: underflow
|
ERROR: type "real" value out of range: underflow
|
||||||
-- bad input
|
-- bad input
|
||||||
|
INSERT INTO FLOAT4_TBL(f1) VALUES ('');
|
||||||
|
ERROR: invalid input syntax for type real: ""
|
||||||
INSERT INTO FLOAT4_TBL(f1) VALUES (' ');
|
INSERT INTO FLOAT4_TBL(f1) VALUES (' ');
|
||||||
ERROR: invalid input syntax for type real: " "
|
ERROR: invalid input syntax for type real: " "
|
||||||
INSERT INTO FLOAT4_TBL(f1) VALUES ('xyz');
|
INSERT INTO FLOAT4_TBL(f1) VALUES ('xyz');
|
||||||
|
|
|
@ -17,6 +17,8 @@ ERROR: type "real" value out of range: underflow
|
||||||
INSERT INTO FLOAT4_TBL(f1) VALUES ('-10e-40');
|
INSERT INTO FLOAT4_TBL(f1) VALUES ('-10e-40');
|
||||||
ERROR: type "real" value out of range: underflow
|
ERROR: type "real" value out of range: underflow
|
||||||
-- bad input
|
-- bad input
|
||||||
|
INSERT INTO FLOAT4_TBL(f1) VALUES ('');
|
||||||
|
ERROR: invalid input syntax for type real: ""
|
||||||
INSERT INTO FLOAT4_TBL(f1) VALUES (' ');
|
INSERT INTO FLOAT4_TBL(f1) VALUES (' ');
|
||||||
ERROR: invalid input syntax for type real: " "
|
ERROR: invalid input syntax for type real: " "
|
||||||
INSERT INTO FLOAT4_TBL(f1) VALUES ('xyz');
|
INSERT INTO FLOAT4_TBL(f1) VALUES ('xyz');
|
||||||
|
|
|
@ -17,6 +17,8 @@ ERROR: "10e-400" is out of range for type double precision
|
||||||
SELECT '-10e-400'::float8;
|
SELECT '-10e-400'::float8;
|
||||||
ERROR: "-10e-400" is out of range for type double precision
|
ERROR: "-10e-400" is out of range for type double precision
|
||||||
-- bad input
|
-- bad input
|
||||||
|
INSERT INTO FLOAT8_TBL(f1) VALUES ('');
|
||||||
|
ERROR: invalid input syntax for type double precision: ""
|
||||||
INSERT INTO FLOAT8_TBL(f1) VALUES (' ');
|
INSERT INTO FLOAT8_TBL(f1) VALUES (' ');
|
||||||
ERROR: invalid input syntax for type double precision: " "
|
ERROR: invalid input syntax for type double precision: " "
|
||||||
INSERT INTO FLOAT8_TBL(f1) VALUES ('xyz');
|
INSERT INTO FLOAT8_TBL(f1) VALUES ('xyz');
|
||||||
|
|
|
@ -17,6 +17,8 @@ ERROR: "10e-400" is out of range for type double precision
|
||||||
SELECT '-10e-400'::float8;
|
SELECT '-10e-400'::float8;
|
||||||
ERROR: "-10e-400" is out of range for type double precision
|
ERROR: "-10e-400" is out of range for type double precision
|
||||||
-- bad input
|
-- bad input
|
||||||
|
INSERT INTO FLOAT8_TBL(f1) VALUES ('');
|
||||||
|
ERROR: invalid input syntax for type double precision: ""
|
||||||
INSERT INTO FLOAT8_TBL(f1) VALUES (' ');
|
INSERT INTO FLOAT8_TBL(f1) VALUES (' ');
|
||||||
ERROR: invalid input syntax for type double precision: " "
|
ERROR: invalid input syntax for type double precision: " "
|
||||||
INSERT INTO FLOAT8_TBL(f1) VALUES ('xyz');
|
INSERT INTO FLOAT8_TBL(f1) VALUES ('xyz');
|
||||||
|
|
|
@ -25,6 +25,8 @@ SELECT '-10e-400'::float8;
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- bad input
|
-- bad input
|
||||||
|
INSERT INTO FLOAT8_TBL(f1) VALUES ('');
|
||||||
|
ERROR: invalid input syntax for type double precision: ""
|
||||||
INSERT INTO FLOAT8_TBL(f1) VALUES (' ');
|
INSERT INTO FLOAT8_TBL(f1) VALUES (' ');
|
||||||
ERROR: invalid input syntax for type double precision: " "
|
ERROR: invalid input syntax for type double precision: " "
|
||||||
INSERT INTO FLOAT8_TBL(f1) VALUES ('xyz');
|
INSERT INTO FLOAT8_TBL(f1) VALUES ('xyz');
|
||||||
|
|
|
@ -25,6 +25,8 @@ SELECT '-10e-400'::float8;
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- bad input
|
-- bad input
|
||||||
|
INSERT INTO FLOAT8_TBL(f1) VALUES ('');
|
||||||
|
ERROR: invalid input syntax for type double precision: ""
|
||||||
INSERT INTO FLOAT8_TBL(f1) VALUES (' ');
|
INSERT INTO FLOAT8_TBL(f1) VALUES (' ');
|
||||||
ERROR: invalid input syntax for type double precision: " "
|
ERROR: invalid input syntax for type double precision: " "
|
||||||
INSERT INTO FLOAT8_TBL(f1) VALUES ('xyz');
|
INSERT INTO FLOAT8_TBL(f1) VALUES ('xyz');
|
||||||
|
|
|
@ -17,6 +17,8 @@ ERROR: "10e-400" is out of range for type double precision
|
||||||
SELECT '-10e-400'::float8;
|
SELECT '-10e-400'::float8;
|
||||||
ERROR: "-10e-400" is out of range for type double precision
|
ERROR: "-10e-400" is out of range for type double precision
|
||||||
-- bad input
|
-- bad input
|
||||||
|
INSERT INTO FLOAT8_TBL(f1) VALUES ('');
|
||||||
|
ERROR: invalid input syntax for type double precision: ""
|
||||||
INSERT INTO FLOAT8_TBL(f1) VALUES (' ');
|
INSERT INTO FLOAT8_TBL(f1) VALUES (' ');
|
||||||
ERROR: invalid input syntax for type double precision: " "
|
ERROR: invalid input syntax for type double precision: " "
|
||||||
INSERT INTO FLOAT8_TBL(f1) VALUES ('xyz');
|
INSERT INTO FLOAT8_TBL(f1) VALUES ('xyz');
|
||||||
|
|
|
@ -12,6 +12,10 @@ INSERT INTO OID_TBL(f1) VALUES (' 10 ');
|
||||||
-- leading/trailing hard tab is also allowed
|
-- leading/trailing hard tab is also allowed
|
||||||
INSERT INTO OID_TBL(f1) VALUES (' 15 ');
|
INSERT INTO OID_TBL(f1) VALUES (' 15 ');
|
||||||
-- bad inputs
|
-- bad inputs
|
||||||
|
INSERT INTO OID_TBL(f1) VALUES ('');
|
||||||
|
ERROR: invalid input syntax for type oid: ""
|
||||||
|
INSERT INTO OID_TBL(f1) VALUES (' ');
|
||||||
|
ERROR: invalid input syntax for type oid: " "
|
||||||
INSERT INTO OID_TBL(f1) VALUES ('asdfasd');
|
INSERT INTO OID_TBL(f1) VALUES ('asdfasd');
|
||||||
ERROR: invalid input syntax for type oid: "asdfasd"
|
ERROR: invalid input syntax for type oid: "asdfasd"
|
||||||
INSERT INTO OID_TBL(f1) VALUES ('99asdfasd');
|
INSERT INTO OID_TBL(f1) VALUES ('99asdfasd');
|
||||||
|
@ -22,8 +26,6 @@ INSERT INTO OID_TBL(f1) VALUES (' 5d');
|
||||||
ERROR: invalid input syntax for type oid: " 5d"
|
ERROR: invalid input syntax for type oid: " 5d"
|
||||||
INSERT INTO OID_TBL(f1) VALUES ('5 5');
|
INSERT INTO OID_TBL(f1) VALUES ('5 5');
|
||||||
ERROR: invalid input syntax for type oid: "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');
|
INSERT INTO OID_TBL(f1) VALUES (' - 500');
|
||||||
ERROR: invalid input syntax for type oid: " - 500"
|
ERROR: invalid input syntax for type oid: " - 500"
|
||||||
INSERT INTO OID_TBL(f1) VALUES ('32958209582039852935');
|
INSERT INTO OID_TBL(f1) VALUES ('32958209582039852935');
|
||||||
|
|
|
@ -17,6 +17,7 @@ INSERT INTO FLOAT4_TBL(f1) VALUES ('10e-40');
|
||||||
INSERT INTO FLOAT4_TBL(f1) VALUES ('-10e-40');
|
INSERT INTO FLOAT4_TBL(f1) VALUES ('-10e-40');
|
||||||
|
|
||||||
-- bad input
|
-- bad input
|
||||||
|
INSERT INTO FLOAT4_TBL(f1) VALUES ('');
|
||||||
INSERT INTO FLOAT4_TBL(f1) VALUES (' ');
|
INSERT INTO FLOAT4_TBL(f1) VALUES (' ');
|
||||||
INSERT INTO FLOAT4_TBL(f1) VALUES ('xyz');
|
INSERT INTO FLOAT4_TBL(f1) VALUES ('xyz');
|
||||||
INSERT INTO FLOAT4_TBL(f1) VALUES ('5.0.0');
|
INSERT INTO FLOAT4_TBL(f1) VALUES ('5.0.0');
|
||||||
|
|
|
@ -17,6 +17,7 @@ SELECT '10e-400'::float8;
|
||||||
SELECT '-10e-400'::float8;
|
SELECT '-10e-400'::float8;
|
||||||
|
|
||||||
-- bad input
|
-- bad input
|
||||||
|
INSERT INTO FLOAT8_TBL(f1) VALUES ('');
|
||||||
INSERT INTO FLOAT8_TBL(f1) VALUES (' ');
|
INSERT INTO FLOAT8_TBL(f1) VALUES (' ');
|
||||||
INSERT INTO FLOAT8_TBL(f1) VALUES ('xyz');
|
INSERT INTO FLOAT8_TBL(f1) VALUES ('xyz');
|
||||||
INSERT INTO FLOAT8_TBL(f1) VALUES ('5.0.0');
|
INSERT INTO FLOAT8_TBL(f1) VALUES ('5.0.0');
|
||||||
|
|
|
@ -15,13 +15,13 @@ INSERT INTO OID_TBL(f1) VALUES (' 10 ');
|
||||||
INSERT INTO OID_TBL(f1) VALUES (' 15 ');
|
INSERT INTO OID_TBL(f1) VALUES (' 15 ');
|
||||||
|
|
||||||
-- bad inputs
|
-- bad inputs
|
||||||
|
INSERT INTO OID_TBL(f1) VALUES ('');
|
||||||
|
INSERT INTO OID_TBL(f1) VALUES (' ');
|
||||||
INSERT INTO OID_TBL(f1) VALUES ('asdfasd');
|
INSERT INTO OID_TBL(f1) VALUES ('asdfasd');
|
||||||
INSERT INTO OID_TBL(f1) VALUES ('99asdfasd');
|
INSERT INTO OID_TBL(f1) VALUES ('99asdfasd');
|
||||||
INSERT INTO OID_TBL(f1) VALUES ('5 d');
|
INSERT INTO OID_TBL(f1) VALUES ('5 d');
|
||||||
INSERT INTO OID_TBL(f1) VALUES (' 5d');
|
INSERT INTO OID_TBL(f1) VALUES (' 5d');
|
||||||
INSERT INTO OID_TBL(f1) VALUES ('5 5');
|
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 (' - 500');
|
||||||
INSERT INTO OID_TBL(f1) VALUES ('32958209582039852935');
|
INSERT INTO OID_TBL(f1) VALUES ('32958209582039852935');
|
||||||
INSERT INTO OID_TBL(f1) VALUES ('-23582358720398502385');
|
INSERT INTO OID_TBL(f1) VALUES ('-23582358720398502385');
|
||||||
|
|
Loading…
Reference in New Issue