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

Commit6c61af6

Browse files
committed
Remove arithmetic operators on the 1-byte-char datatype, as per proposals
made several times in the past. Add coercion functions between "char"and integer so that a workaround is possible if needed.Initdb forced.
1 parent1ab4155 commit6c61af6

File tree

7 files changed

+56
-53
lines changed

7 files changed

+56
-53
lines changed

‎doc/src/sgml/release.sgml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/release.sgml,v 1.299 2004/10/0414:42:46 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/release.sgml,v 1.300 2004/10/0422:49:47 tgl Exp $
33
-->
44

55
<appendix id="release">
@@ -263,6 +263,13 @@ $PostgreSQL: pgsql/doc/src/sgml/release.sgml,v 1.299 2004/10/04 14:42:46 tgl Exp
263263
</para>
264264
</listitem>
265265

266+
<listitem>
267+
<para>
268+
The arithmetic operators associated with the <quote>char</> data type
269+
have been removed.
270+
</para>
271+
</listitem>
272+
266273
<listitem>
267274
<para>
268275
The server now warns of empty strings passed to
@@ -1241,6 +1248,19 @@ $PostgreSQL: pgsql/doc/src/sgml/release.sgml,v 1.299 2004/10/04 14:42:46 tgl Exp
12411248
</para>
12421249
</listitem>
12431250

1251+
<listitem>
1252+
<para>
1253+
The arithmetic operators associated with the <quote>char</> data type
1254+
have been removed.
1255+
</para>
1256+
<para>
1257+
Formerly, the parser would select these operators in many situations
1258+
where an <quote>unable to select an operator</> error would be more
1259+
appropriate, such as <literal>null * null</>. If you actually want
1260+
to do arithmetic on a <quote>char</> column, you can cast it to integer.
1261+
</para>
1262+
</listitem>
1263+
12441264
<listitem>
12451265
<para>
12461266
Syntax checking of array input values considerably tightened up (Joe)

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

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,25 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/utils/adt/char.c,v 1.40 2004/08/29 04:12:51momjian Exp $
12+
* $PostgreSQL: pgsql/src/backend/utils/adt/char.c,v 1.41 2004/10/04 22:49:51tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
1616
#include"postgres.h"
1717

18+
#include<limits.h>
19+
1820
#include"libpq/pqformat.h"
1921
#include"utils/builtins.h"
2022

23+
#ifndefSCHAR_MAX
24+
#defineSCHAR_MAX (0x7F)
25+
#endif
26+
#ifndefSCHAR_MIN
27+
#defineSCHAR_MIN (-SCHAR_MAX-1)
28+
#endif
29+
30+
2131
/*****************************************************************************
2232
* USER I/O ROUTINES *
2333
*****************************************************************************/
@@ -88,7 +98,7 @@ charsend(PG_FUNCTION_ARGS)
8898

8999
/*
90100
* NOTE: comparisons are done as though char is unsigned (uint8).
91-
*Arithmetic is done as though char is signed (int8).
101+
*Conversions to and from integer are done as though char is signed (int8).
92102
*
93103
* You wanted consistency?
94104
*/
@@ -147,45 +157,26 @@ charge(PG_FUNCTION_ARGS)
147157
PG_RETURN_BOOL((uint8)arg1 >= (uint8)arg2);
148158
}
149159

150-
Datum
151-
charpl(PG_FUNCTION_ARGS)
152-
{
153-
chararg1=PG_GETARG_CHAR(0);
154-
chararg2=PG_GETARG_CHAR(1);
155-
156-
PG_RETURN_CHAR((int8)arg1+ (int8)arg2);
157-
}
158160

159161
Datum
160-
charmi(PG_FUNCTION_ARGS)
162+
chartoi4(PG_FUNCTION_ARGS)
161163
{
162164
chararg1=PG_GETARG_CHAR(0);
163-
chararg2=PG_GETARG_CHAR(1);
164165

165-
PG_RETURN_CHAR((int8)arg1- (int8)arg2);
166+
PG_RETURN_INT32((int32) ((int8)arg1));
166167
}
167168

168169
Datum
169-
charmul(PG_FUNCTION_ARGS)
170+
i4tochar(PG_FUNCTION_ARGS)
170171
{
171-
chararg1=PG_GETARG_CHAR(0);
172-
chararg2=PG_GETARG_CHAR(1);
173-
174-
PG_RETURN_CHAR((int8)arg1* (int8)arg2);
175-
}
176-
177-
Datum
178-
chardiv(PG_FUNCTION_ARGS)
179-
{
180-
chararg1=PG_GETARG_CHAR(0);
181-
chararg2=PG_GETARG_CHAR(1);
172+
int32arg1=PG_GETARG_INT32(0);
182173

183-
if (arg2==0)
174+
if (arg1<SCHAR_MIN||arg1>SCHAR_MAX)
184175
ereport(ERROR,
185-
(errcode(ERRCODE_DIVISION_BY_ZERO),
186-
errmsg("division by zero")));
176+
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
177+
errmsg("\"char\" out of range")));
187178

188-
PG_RETURN_CHAR((int8)arg1 / (int8)arg2);
179+
PG_RETURN_CHAR((int8)arg1);
189180
}
190181

191182

‎src/include/catalog/catversion.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
3838
* Portions Copyright (c) 1994, Regents of the University of California
3939
*
40-
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.249 2004/08/29 04:13:04 momjian Exp $
40+
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.250 2004/10/04 22:49:54 tgl Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/*yyyymmddN */
56-
#defineCATALOG_VERSION_NO200408031
56+
#defineCATALOG_VERSION_NO200410041
5757

5858
#endif

‎src/include/catalog/pg_cast.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
* Copyright (c) 2002-2004, PostgreSQL Global Development Group
1212
*
13-
* $PostgreSQL: pgsql/src/include/catalog/pg_cast.h,v 1.15 2004/08/29 05:06:55 momjian Exp $
13+
* $PostgreSQL: pgsql/src/include/catalog/pg_cast.h,v 1.16 2004/10/04 22:49:54 tgl Exp $
1414
*
1515
* NOTES
1616
* the genbki.sh script reads this file and generates .bki
@@ -182,6 +182,9 @@ DATA(insert ( 1043 18 944 a ));
182182
DATA(insert (2519407i ));
183183
DATA(insert (104219409i ));
184184
DATA(insert (1043191400i ));
185+
/* Cross-category casts between int4 and "char" */
186+
DATA(insert (182377e ));
187+
DATA(insert (231878e ));
185188

186189
/*
187190
* Datetime category

‎src/include/catalog/pg_operator.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
99
* Portions Copyright (c) 1994, Regents of the University of California
1010
*
11-
* $PostgreSQL: pgsql/src/include/catalog/pg_operator.h,v 1.128 2004/08/29 05:06:55 momjian Exp $
11+
* $PostgreSQL: pgsql/src/include/catalog/pg_operator.h,v 1.129 2004/10/04 22:49:54 tgl Exp $
1212
*
1313
* NOTES
1414
* the genbki.sh script reads this file and generates .bki
@@ -299,11 +299,6 @@ DATA(insert OID = 632 ( "<=" PGNSP PGUID b f181816 634 6330 0 0 0 charle
299299
DATA(insertOID=633 (">"PGNSPPGUIDbf1818166316320000chargtscalargtselscalargtjoinsel ));
300300
DATA(insertOID=634 (">="PGNSPPGUIDbf1818166326310000chargescalargtselscalargtjoinsel ));
301301

302-
DATA(insertOID=635 ("+"PGNSPPGUIDbf181818000000charpl-- ));
303-
DATA(insertOID=636 ("-"PGNSPPGUIDbf181818000000charmi-- ));
304-
DATA(insertOID=637 ("*"PGNSPPGUIDbf181818000000charmul-- ));
305-
DATA(insertOID=638 ("/"PGNSPPGUIDbf181818000000chardiv-- ));
306-
307302
DATA(insertOID=639 ("~"PGNSPPGUIDbf19251606400000nameregexeqregexeqselregexeqjoinsel ));
308303
#defineOID_NAME_REGEXEQ_OP639
309304
DATA(insertOID=640 ("!~"PGNSPPGUIDbf19251606390000nameregexneregexneselregexnejoinsel ));

‎src/include/catalog/pg_proc.h

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.346 2004/10/04 22:13:14 tgl Exp $
10+
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.347 2004/10/04 22:49:55 tgl Exp $
1111
*
1212
* NOTES
1313
* The script catalog/genbki.sh reads this file and generates .bki
@@ -181,14 +181,10 @@ DATA(insert OID = 73 ( chargt PGNSP PGUID 12 f f t f i 2 16 "18 18" _null
181181
DESCR("greater-than");
182182
DATA(insertOID=74 (chargePGNSPPGUID12fftfi216"18 18"_null_charge-_null_ ));
183183
DESCR("greater-than-or-equal");
184-
DATA(insertOID=1248 (charplPGNSPPGUID12fftfi218"18 18"_null_charpl-_null_ ));
185-
DESCR("add");
186-
DATA(insertOID=1250 (charmiPGNSPPGUID12fftfi218"18 18"_null_charmi-_null_ ));
187-
DESCR("subtract");
188-
DATA(insertOID=77 (charmulPGNSPPGUID12fftfi218"18 18"_null_charmul-_null_ ));
189-
DESCR("multiply");
190-
DATA(insertOID=78 (chardivPGNSPPGUID12fftfi218"18 18"_null_chardiv-_null_ ));
191-
DESCR("divide");
184+
DATA(insertOID=77 (int4PGNSPPGUID12fftfi123"18"_null_chartoi4-_null_ ));
185+
DESCR("convert char to int4");
186+
DATA(insertOID=78 (charPGNSPPGUID12fftfi118"23"_null_i4tochar-_null_ ));
187+
DESCR("convert int4 to char");
192188

193189
DATA(insertOID=79 (nameregexeqPGNSPPGUID12fftfi216"19 25"_null_nameregexeq-_null_ ));
194190
DESCR("matches regex., case-sensitive");

‎src/include/utils/builtins.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/utils/builtins.h,v 1.250 2004/08/30 02:54:40 momjian Exp $
10+
* $PostgreSQL: pgsql/src/include/utils/builtins.h,v 1.251 2004/10/04 22:49:59 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -88,10 +88,8 @@ extern Datum charlt(PG_FUNCTION_ARGS);
8888
externDatumcharle(PG_FUNCTION_ARGS);
8989
externDatumchargt(PG_FUNCTION_ARGS);
9090
externDatumcharge(PG_FUNCTION_ARGS);
91-
externDatumcharpl(PG_FUNCTION_ARGS);
92-
externDatumcharmi(PG_FUNCTION_ARGS);
93-
externDatumcharmul(PG_FUNCTION_ARGS);
94-
externDatumchardiv(PG_FUNCTION_ARGS);
91+
externDatumchartoi4(PG_FUNCTION_ARGS);
92+
externDatumi4tochar(PG_FUNCTION_ARGS);
9593
externDatumtext_char(PG_FUNCTION_ARGS);
9694
externDatumchar_text(PG_FUNCTION_ARGS);
9795

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp