This patch changes the input routines for float4, float8 and oid to
reject empty strings (rather than treating them as 0). In 8.0 we issue
a warning about this behavior and indicate that the input will not be
accepted by a future release, so it seems reasonable to disallow the
input in 8.1. The patch also updates the regression tests.
Barring any objections, I'll apply this to HEAD tomorrow.
-Neil
Index: src/backend/utils/adt/float.c
===
RCS file: /var/lib/cvs/pgsql/src/backend/utils/adt/float.c,v
retrieving revision 1.112
diff -c -r1.112 float.c
*** src/backend/utils/adt/float.c 31 Dec 2004 22:01:21 - 1.112
--- src/backend/utils/adt/float.c 11 Feb 2005 01:10:19 -
***
*** 267,287
/*
* Check for an empty-string input to begin with, to avoid the
* 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')
! {
! 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.)));
! PG_RETURN_FLOAT4((float4) 0.0);
! }
/* skip leading whitespace */
while (*num != '\0' isspace((unsigned char) *num))
--- 267,278
/*
* Check for an empty-string input to begin with, to avoid the
* vagaries of strtod() on different platforms.
*/
if (*num == '\0')
! ereport(ERROR,
! (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
! errmsg(invalid input syntax for type real: \%s\,
! orig_num)));
/* skip leading whitespace */
while (*num != '\0' isspace((unsigned char) *num))
***
*** 444,464
/*
* Check for an empty-string input to begin with, to avoid the
* 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')
! {
! 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.)));
! PG_RETURN_FLOAT8(0.0);
! }
/* skip leading whitespace */
while (*num != '\0' isspace((unsigned char) *num))
--- 435,446
/*
* Check for an empty-string input to begin with, to avoid the
* vagaries of strtod() on different platforms.
*/
if (*num == '\0')
! ereport(ERROR,
! (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
! errmsg(invalid input syntax for type double precision: \%s\,
! orig_num)));
/* skip leading whitespace */
while (*num != '\0' isspace((unsigned char) *num))
Index: src/backend/utils/adt/oid.c
===
RCS file: /var/lib/cvs/pgsql/src/backend/utils/adt/oid.c,v
retrieving revision 1.60
diff -c -r1.60 oid.c
*** src/backend/utils/adt/oid.c 31 Dec 2004 22:01:22 - 1.60
--- src/backend/utils/adt/oid.c 11 Feb 2005 01:09:14 -
***
*** 33,50
char *endptr;
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')
! 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);
--- 33,43
char *endptr;
Oid result;
if (*s == '\0')
! ereport(ERROR,
! (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
! errmsg(invalid input syntax for type oid: \%s\,
! s)));
errno = 0;
cvt = strtoul(s, endptr, 10);
Index: src/test/regress/expected/float4-exp-three-digits.out
===
RCS file: /var/lib/cvs/pgsql/src/test/regress/expected/float4-exp-three-digits.out,v
retrieving revision 1.5
diff -c -r1.5 float4-exp-three-digits.out
*** src/test/regress/expected/float4-exp-three-digits.out 15 Mar 2004 16:20:51 - 1.5
--- src/test/regress/expected/float4-exp-three-digits.out 11 Feb 2005 01:17:06 -
***
*** 31,36
--- 31,38
ERROR: invalid input syntax for type real: -