Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2146bfc

Browse files
author
Neil Conway
committed
Emit a warning when an empty string is input to the oid, float4, and
float8 types. This begins the deprecation of this feature: in 7.6,this input will be rejected.Also added a new error code for warnings about deprecated features,and updated the regression tests.
1 parent0b1f7cc commit2146bfc

File tree

6 files changed

+54
-18
lines changed

6 files changed

+54
-18
lines changed

‎doc/src/sgml/errcodes.sgml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/errcodes.sgml,v 1.2 2003/11/29 19:51:37 pgsql Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/errcodes.sgml,v 1.3 2004/03/04 21:47:18 neilc Exp $ -->
22

33
<appendix id="errcodes-appendix">
44
<title><productname>PostgreSQL</productname> Error Codes</title>
@@ -95,6 +95,10 @@
9595
<entry>WARNING STRING DATA RIGHT TRUNCATION</entry>
9696
</row>
9797

98+
<row>
99+
<entry><literal>01P01</literal></entry>
100+
<entry>WARNING DEPRECATED FEATURE</entry>
101+
</row>
98102

99103
<row>
100104
<entry>Class 02</entry>

‎src/backend/utils/adt/float.c

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/float.c,v 1.96 2003/11/29 19:51:58 pgsql Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/float.c,v 1.97 2004/03/04 21:47:18 neilc Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -208,6 +208,19 @@ float4in(PG_FUNCTION_ARGS)
208208
errmsg("\"%s\" is out of range for type real",num)));
209209
}
210210

211+
/*
212+
* In releases prior to 7.5, we accepted an empty string as valid
213+
* input (yielding a float4 of 0). In 7.5, we accept empty
214+
* strings, but emit a warning noting that the feature is
215+
* deprecated. In 7.6+, the warning should be replaced by an error.
216+
*/
217+
if (num==endptr)
218+
ereport(WARNING,
219+
(errcode(ERRCODE_WARNING_DEPRECATED_FEATURE),
220+
errmsg("deprecated input syntax for type real: \"\""),
221+
errdetail("This input will be rejected in "
222+
"a future release of PostgreSQL.")));
223+
211224
/*
212225
* if we get here, we have a legal double, still need to check to see
213226
* if it's a legal float
@@ -309,6 +322,19 @@ float8in(PG_FUNCTION_ARGS)
309322
errmsg("\"%s\" is out of range for type double precision",num)));
310323
}
311324

325+
/*
326+
* In releases prior to 7.5, we accepted an empty string as valid
327+
* input (yielding a float8 of 0). In 7.5, we accept empty
328+
* strings, but emit a warning noting that the feature is
329+
* deprecated. In 7.6+, the warning should be replaced by an error.
330+
*/
331+
if (num==endptr)
332+
ereport(WARNING,
333+
(errcode(ERRCODE_WARNING_DEPRECATED_FEATURE),
334+
errmsg("deprecated input syntax for type double precision: \"\""),
335+
errdetail("This input will be rejected in "
336+
"a future release of PostgreSQL.")));
337+
312338
CheckFloat8Val(val);
313339

314340
PG_RETURN_FLOAT8(val);

‎src/backend/utils/adt/oid.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/oid.c,v 1.54 2004/02/18 00:01:34 neilc Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/oid.c,v 1.55 2004/03/04 21:47:18 neilc Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -40,15 +40,27 @@ oidin_subr(const char *funcname, const char *s, char **endloc)
4040
* strtoul() normally only sets ERANGE. On some systems it also may
4141
* set EINVAL, which simply means it couldn't parse the input string.
4242
* This is handled by the second "if" consistent across platforms.
43-
* Note that for historical reasons we accept an empty string as
44-
* meaning 0.
4543
*/
4644
if (errno&&errno!=ERANGE&&errno!=EINVAL)
4745
ereport(ERROR,
4846
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
4947
errmsg("invalid input syntax for type oid: \"%s\"",
5048
s)));
51-
if (endptr==s&&*endptr)
49+
50+
/*
51+
* In releases prior to 7.5, we accepted an empty string as valid
52+
* input (yielding an OID of 0). In 7.5, we accept empty strings,
53+
* but emit a warning noting that the feature is deprecated. In
54+
* 7.6+, the warning should be replaced by an error.
55+
*/
56+
if (*s=='\0')
57+
ereport(WARNING,
58+
(errcode(ERRCODE_WARNING_DEPRECATED_FEATURE),
59+
errmsg("deprecated input syntax for type oid: \"\""),
60+
errdetail("This input will be rejected in "
61+
"a future release of PostgreSQL.")));
62+
63+
if (endptr==s&&*s)
5264
ereport(ERROR,
5365
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
5466
errmsg("invalid input syntax for type oid: \"%s\"",

‎src/include/utils/errcodes.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
* Copyright (c) 2003, PostgreSQL Global Development Group
1313
*
14-
* $PostgreSQL: pgsql/src/include/utils/errcodes.h,v 1.7 2003/11/29 22:41:15 pgsql Exp $
14+
* $PostgreSQL: pgsql/src/include/utils/errcodes.h,v 1.8 2004/03/04 21:47:18 neilc Exp $
1515
*
1616
*-------------------------------------------------------------------------
1717
*/
@@ -44,6 +44,7 @@
4444
#defineERRCODE_WARNING_IMPLICIT_ZERO_BIT_PADDINGMAKE_SQLSTATE('0','1', '0','0','8')
4545
#defineERRCODE_WARNING_NULL_VALUE_ELIMINATED_IN_SET_FUNCTIONMAKE_SQLSTATE('0','1', '0','0','3')
4646
#defineERRCODE_WARNING_STRING_DATA_RIGHT_TRUNCATIONMAKE_SQLSTATE('0','1', '0','0','4')
47+
#defineERRCODE_WARNING_DEPRECATED_FEATUREMAKE_SQLSTATE('0','1', 'P','0','1')
4748

4849
/* Class 02 - No Data --- this is also a warning class per SQL99 */
4950
/* (do not use this class for failure conditions!) */

‎src/test/regress/expected/oid.out

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ INSERT INTO OID_TBL(f1) VALUES ('1235');
77
INSERT INTO OID_TBL(f1) VALUES ('987');
88
INSERT INTO OID_TBL(f1) VALUES ('-1040');
99
INSERT INTO OID_TBL(f1) VALUES ('99999999');
10-
INSERT INTO OID_TBL(f1) VALUES ('');
1110
-- bad inputs
1211
INSERT INTO OID_TBL(f1) VALUES ('asdfasd');
1312
ERROR: invalid input syntax for type oid: "asdfasd"
@@ -21,8 +20,7 @@ SELECT '' AS six, OID_TBL.*;
2120
| 987
2221
| 4294966256
2322
| 99999999
24-
| 0
25-
(6 rows)
23+
(5 rows)
2624

2725
SELECT '' AS one, o.* FROM OID_TBL o WHERE o.f1 = 1234;
2826
one | f1
@@ -37,23 +35,20 @@ SELECT '' AS five, o.* FROM OID_TBL o WHERE o.f1 <> '1234';
3735
| 987
3836
| 4294966256
3937
| 99999999
40-
| 0
41-
(5 rows)
38+
(4 rows)
4239

4340
SELECT '' AS three, o.* FROM OID_TBL o WHERE o.f1 <= '1234';
4441
three | f1
4542
-------+------
4643
| 1234
4744
| 987
48-
| 0
49-
(3 rows)
45+
(2 rows)
5046

5147
SELECT '' AS two, o.* FROM OID_TBL o WHERE o.f1 < '1234';
5248
two | f1
5349
-----+-----
5450
| 987
55-
| 0
56-
(2 rows)
51+
(1 row)
5752

5853
SELECT '' AS four, o.* FROM OID_TBL o WHERE o.f1 >= '1234';
5954
four | f1

‎src/test/regress/sql/oid.sql

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ INSERT INTO OID_TBL(f1) VALUES ('-1040');
1414

1515
INSERT INTO OID_TBL(f1)VALUES ('99999999');
1616

17-
INSERT INTO OID_TBL(f1)VALUES ('');
18-
1917
-- bad inputs
2018

2119
INSERT INTO OID_TBL(f1)VALUES ('asdfasd');

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp