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 -0000	1.112
--- src/backend/utils/adt/float.c	11 Feb 2005 01:10:19 -0000
***************
*** 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 -0000	1.60
--- src/backend/utils/adt/oid.c	11 Feb 2005 01:09:14 -0000
***************
*** 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 -0000	1.5
--- src/test/regress/expected/float4-exp-three-digits.out	11 Feb 2005 01:17:06 -0000
***************
*** 31,36 ****
--- 31,38 ----
  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"
+ INSERT INTO FLOAT4_TBL(f1) VALUES ('');
+ ERROR:  invalid input syntax for type real: ""
  -- special inputs
  SELECT 'NaN'::float4;
   float4 
Index: src/test/regress/expected/float4.out
===================================================================
RCS file: /var/lib/cvs/pgsql/src/test/regress/expected/float4.out,v
retrieving revision 1.11
diff -c -r1.11 float4.out
*** src/test/regress/expected/float4.out	12 Mar 2004 00:25:40 -0000	1.11
--- src/test/regress/expected/float4.out	11 Feb 2005 01:13:40 -0000
***************
*** 31,36 ****
--- 31,38 ----
  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"
+ INSERT INTO FLOAT4_TBL(f1) VALUES ('');
+ ERROR:  invalid input syntax for type real: ""
  -- special inputs
  SELECT 'NaN'::float4;
   float4 
Index: src/test/regress/expected/float8-exp-three-digits-win32.out
===================================================================
RCS file: /var/lib/cvs/pgsql/src/test/regress/expected/float8-exp-three-digits-win32.out,v
retrieving revision 1.4
diff -c -r1.4 float8-exp-three-digits-win32.out
*** src/test/regress/expected/float8-exp-three-digits-win32.out	23 Apr 2004 20:32:20 -0000	1.4
--- src/test/regress/expected/float8-exp-three-digits-win32.out	11 Feb 2005 01:17:59 -0000
***************
*** 31,36 ****
--- 31,38 ----
  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"
+ INSERT INTO FLOAT8_TBL(f1) VALUES ('');
+ ERROR:  invalid input syntax for type double precision: ""
  -- special inputs
  SELECT 'NaN'::float8;
   float8 
Index: src/test/regress/expected/float8-exp-three-digits.out
===================================================================
RCS file: /var/lib/cvs/pgsql/src/test/regress/expected/float8-exp-three-digits.out,v
retrieving revision 1.9
diff -c -r1.9 float8-exp-three-digits.out
*** src/test/regress/expected/float8-exp-three-digits.out	23 Apr 2004 20:32:20 -0000	1.9
--- src/test/regress/expected/float8-exp-three-digits.out	11 Feb 2005 01:17:26 -0000
***************
*** 31,36 ****
--- 31,38 ----
  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"
+ INSERT INTO FLOAT8_TBL(f1) VALUES ('');
+ ERROR:  invalid input syntax for type double precision: ""
  -- special inputs
  SELECT 'NaN'::float8;
   float8
Index: src/test/regress/expected/float8-small-is-zero.out
===================================================================
RCS file: /var/lib/cvs/pgsql/src/test/regress/expected/float8-small-is-zero.out,v
retrieving revision 1.7
diff -c -r1.7 float8-small-is-zero.out
*** src/test/regress/expected/float8-small-is-zero.out	23 Apr 2004 20:32:20 -0000	1.7
--- src/test/regress/expected/float8-small-is-zero.out	11 Feb 2005 01:18:11 -0000
***************
*** 39,44 ****
--- 39,46 ----
  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"
+ INSERT INTO FLOAT8_TBL(f1) VALUES ('');
+ ERROR:  invalid input syntax for type double precision: ""
  -- special inputs
  SELECT 'NaN'::float8;
   float8 
Index: src/test/regress/expected/float8-small-is-zero_1.out
===================================================================
RCS file: /var/lib/cvs/pgsql/src/test/regress/expected/float8-small-is-zero_1.out,v
retrieving revision 1.1
diff -c -r1.1 float8-small-is-zero_1.out
*** src/test/regress/expected/float8-small-is-zero_1.out	17 Nov 2004 17:25:32 -0000	1.1
--- src/test/regress/expected/float8-small-is-zero_1.out	11 Feb 2005 01:22:21 -0000
***************
*** 39,44 ****
--- 39,46 ----
  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"
+ INSERT INTO FLOAT8_TBL(f1) VALUES ('');
+ ERROR:  invalid input syntax for type double precision: ""
  -- special inputs
  SELECT 'NaN'::float8;
   float8 
Index: src/test/regress/expected/float8.out
===================================================================
RCS file: /var/lib/cvs/pgsql/src/test/regress/expected/float8.out,v
retrieving revision 1.21
diff -c -r1.21 float8.out
*** src/test/regress/expected/float8.out	23 Apr 2004 20:32:20 -0000	1.21
--- src/test/regress/expected/float8.out	11 Feb 2005 01:13:43 -0000
***************
*** 31,36 ****
--- 31,38 ----
  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"
+ INSERT INTO FLOAT8_TBL(f1) VALUES ('');
+ ERROR:  invalid input syntax for type double precision: ""
  -- special inputs
  SELECT 'NaN'::float8;
   float8 
Index: src/test/regress/expected/oid.out
===================================================================
RCS file: /var/lib/cvs/pgsql/src/test/regress/expected/oid.out,v
retrieving revision 1.10
diff -c -r1.10 oid.out
*** src/test/regress/expected/oid.out	11 Mar 2004 02:11:13 -0000	1.10
--- src/test/regress/expected/oid.out	11 Feb 2005 01:13:55 -0000
***************
*** 30,35 ****
--- 30,37 ----
  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
+ INSERT INTO OID_TBL(f1) VALUES ('');
+ ERROR:  invalid input syntax for type oid: ""
  SELECT '' AS six, OID_TBL.*;
   six |     f1     
  -----+------------
Index: src/test/regress/sql/float4.sql
===================================================================
RCS file: /var/lib/cvs/pgsql/src/test/regress/sql/float4.sql,v
retrieving revision 1.6
diff -c -r1.6 float4.sql
*** src/test/regress/sql/float4.sql	12 Mar 2004 00:25:42 -0000	1.6
--- src/test/regress/sql/float4.sql	11 Feb 2005 01:11:59 -0000
***************
*** 24,29 ****
--- 24,30 ----
  INSERT INTO FLOAT4_TBL(f1) VALUES ('5.   0');
  INSERT INTO FLOAT4_TBL(f1) VALUES ('     - 3.0');
  INSERT INTO FLOAT4_TBL(f1) VALUES ('123            5');
+ INSERT INTO FLOAT4_TBL(f1) VALUES ('');
  
  -- special inputs
  SELECT 'NaN'::float4;
Index: src/test/regress/sql/float8.sql
===================================================================
RCS file: /var/lib/cvs/pgsql/src/test/regress/sql/float8.sql,v
retrieving revision 1.12
diff -c -r1.12 float8.sql
*** src/test/regress/sql/float8.sql	23 Apr 2004 20:32:20 -0000	1.12
--- src/test/regress/sql/float8.sql	11 Feb 2005 01:12:16 -0000
***************
*** 24,29 ****
--- 24,30 ----
  INSERT INTO FLOAT8_TBL(f1) VALUES ('5.   0');
  INSERT INTO FLOAT8_TBL(f1) VALUES ('    - 3');
  INSERT INTO FLOAT8_TBL(f1) VALUES ('123           5');
+ INSERT INTO FLOAT8_TBL(f1) VALUES ('');
  
  -- special inputs
  SELECT 'NaN'::float8;
Index: src/test/regress/sql/oid.sql
===================================================================
RCS file: /var/lib/cvs/pgsql/src/test/regress/sql/oid.sql,v
retrieving revision 1.6
diff -c -r1.6 oid.sql
*** src/test/regress/sql/oid.sql	11 Mar 2004 02:11:14 -0000	1.6
--- src/test/regress/sql/oid.sql	11 Feb 2005 01:12:31 -0000
***************
*** 15,21 ****
  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');
--- 15,20 ----
***************
*** 25,30 ****
--- 24,30 ----
  INSERT INTO OID_TBL(f1) VALUES (' - 500');
  INSERT INTO OID_TBL(f1) VALUES ('32958209582039852935');
  INSERT INTO OID_TBL(f1) VALUES ('-23582358720398502385');
+ INSERT INTO OID_TBL(f1) VALUES ('');
  
  SELECT '' AS six, OID_TBL.*;
  
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

               http://www.postgresql.org/docs/faq

Reply via email to