Commit 6c61af66 authored by Tom Lane's avatar Tom Lane

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.
parent 1ab41559
<!-- <!--
$PostgreSQL: pgsql/doc/src/sgml/release.sgml,v 1.299 2004/10/04 14:42:46 tgl Exp $ $PostgreSQL: pgsql/doc/src/sgml/release.sgml,v 1.300 2004/10/04 22:49:47 tgl Exp $
--> -->
<appendix id="release"> <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 ...@@ -263,6 +263,13 @@ $PostgreSQL: pgsql/doc/src/sgml/release.sgml,v 1.299 2004/10/04 14:42:46 tgl Exp
</para> </para>
</listitem> </listitem>
<listitem>
<para>
The arithmetic operators associated with the <quote>char</> data type
have been removed.
</para>
</listitem>
<listitem> <listitem>
<para> <para>
The server now warns of empty strings passed to 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 ...@@ -1241,6 +1248,19 @@ $PostgreSQL: pgsql/doc/src/sgml/release.sgml,v 1.299 2004/10/04 14:42:46 tgl Exp
</para> </para>
</listitem> </listitem>
<listitem>
<para>
The arithmetic operators associated with the <quote>char</> data type
have been removed.
</para>
<para>
Formerly, the parser would select these operators in many situations
where an <quote>unable to select an operator</> error would be more
appropriate, such as <literal>null * null</>. If you actually want
to do arithmetic on a <quote>char</> column, you can cast it to integer.
</para>
</listitem>
<listitem> <listitem>
<para> <para>
Syntax checking of array input values considerably tightened up (Joe) Syntax checking of array input values considerably tightened up (Joe)
......
...@@ -9,15 +9,25 @@ ...@@ -9,15 +9,25 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/char.c,v 1.40 2004/08/29 04:12:51 momjian Exp $ * $PostgreSQL: pgsql/src/backend/utils/adt/char.c,v 1.41 2004/10/04 22:49:51 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#include "postgres.h" #include "postgres.h"
#include <limits.h>
#include "libpq/pqformat.h" #include "libpq/pqformat.h"
#include "utils/builtins.h" #include "utils/builtins.h"
#ifndef SCHAR_MAX
#define SCHAR_MAX (0x7F)
#endif
#ifndef SCHAR_MIN
#define SCHAR_MIN (-SCHAR_MAX-1)
#endif
/***************************************************************************** /*****************************************************************************
* USER I/O ROUTINES * * USER I/O ROUTINES *
*****************************************************************************/ *****************************************************************************/
...@@ -88,7 +98,7 @@ charsend(PG_FUNCTION_ARGS) ...@@ -88,7 +98,7 @@ charsend(PG_FUNCTION_ARGS)
/* /*
* NOTE: comparisons are done as though char is unsigned (uint8). * NOTE: comparisons are done as though char is unsigned (uint8).
* Arithmetic is done as though char is signed (int8). * Conversions to and from integer are done as though char is signed (int8).
* *
* You wanted consistency? * You wanted consistency?
*/ */
...@@ -147,45 +157,26 @@ charge(PG_FUNCTION_ARGS) ...@@ -147,45 +157,26 @@ charge(PG_FUNCTION_ARGS)
PG_RETURN_BOOL((uint8) arg1 >= (uint8) arg2); PG_RETURN_BOOL((uint8) arg1 >= (uint8) arg2);
} }
Datum
charpl(PG_FUNCTION_ARGS)
{
char arg1 = PG_GETARG_CHAR(0);
char arg2 = PG_GETARG_CHAR(1);
PG_RETURN_CHAR((int8) arg1 + (int8) arg2);
}
Datum Datum
charmi(PG_FUNCTION_ARGS) chartoi4(PG_FUNCTION_ARGS)
{ {
char arg1 = PG_GETARG_CHAR(0); char arg1 = PG_GETARG_CHAR(0);
char arg2 = PG_GETARG_CHAR(1);
PG_RETURN_CHAR((int8) arg1 - (int8) arg2); PG_RETURN_INT32((int32) ((int8) arg1));
} }
Datum Datum
charmul(PG_FUNCTION_ARGS) i4tochar(PG_FUNCTION_ARGS)
{ {
char arg1 = PG_GETARG_CHAR(0); int32 arg1 = PG_GETARG_INT32(0);
char arg2 = PG_GETARG_CHAR(1);
PG_RETURN_CHAR((int8) arg1 * (int8) arg2);
}
Datum
chardiv(PG_FUNCTION_ARGS)
{
char arg1 = PG_GETARG_CHAR(0);
char arg2 = PG_GETARG_CHAR(1);
if (arg2 == 0) if (arg1 < SCHAR_MIN || arg1 > SCHAR_MAX)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO), (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("division by zero"))); errmsg("\"char\" out of range")));
PG_RETURN_CHAR((int8) arg1 / (int8) arg2); PG_RETURN_CHAR((int8) arg1);
} }
......
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
* Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.249 2004/08/29 04:13:04 momjian Exp $ * $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.250 2004/10/04 22:49:54 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -53,6 +53,6 @@ ...@@ -53,6 +53,6 @@
*/ */
/* yyyymmddN */ /* yyyymmddN */
#define CATALOG_VERSION_NO 200408031 #define CATALOG_VERSION_NO 200410041
#endif #endif
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* *
* Copyright (c) 2002-2004, PostgreSQL Global Development Group * Copyright (c) 2002-2004, PostgreSQL Global Development Group
* *
* $PostgreSQL: pgsql/src/include/catalog/pg_cast.h,v 1.15 2004/08/29 05:06:55 momjian Exp $ * $PostgreSQL: pgsql/src/include/catalog/pg_cast.h,v 1.16 2004/10/04 22:49:54 tgl Exp $
* *
* NOTES * NOTES
* the genbki.sh script reads this file and generates .bki * the genbki.sh script reads this file and generates .bki
...@@ -182,6 +182,9 @@ DATA(insert ( 1043 18 944 a )); ...@@ -182,6 +182,9 @@ DATA(insert ( 1043 18 944 a ));
DATA(insert ( 25 19 407 i )); DATA(insert ( 25 19 407 i ));
DATA(insert ( 1042 19 409 i )); DATA(insert ( 1042 19 409 i ));
DATA(insert ( 1043 19 1400 i )); DATA(insert ( 1043 19 1400 i ));
/* Cross-category casts between int4 and "char" */
DATA(insert ( 18 23 77 e ));
DATA(insert ( 23 18 78 e ));
/* /*
* Datetime category * Datetime category
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/catalog/pg_operator.h,v 1.128 2004/08/29 05:06:55 momjian Exp $ * $PostgreSQL: pgsql/src/include/catalog/pg_operator.h,v 1.129 2004/10/04 22:49:54 tgl Exp $
* *
* NOTES * NOTES
* the genbki.sh script reads this file and generates .bki * the genbki.sh script reads this file and generates .bki
...@@ -299,11 +299,6 @@ DATA(insert OID = 632 ( "<=" PGNSP PGUID b f 18 18 16 634 633 0 0 0 0 charle ...@@ -299,11 +299,6 @@ DATA(insert OID = 632 ( "<=" PGNSP PGUID b f 18 18 16 634 633 0 0 0 0 charle
DATA(insert OID = 633 ( ">" PGNSP PGUID b f 18 18 16 631 632 0 0 0 0 chargt scalargtsel scalargtjoinsel )); DATA(insert OID = 633 ( ">" PGNSP PGUID b f 18 18 16 631 632 0 0 0 0 chargt scalargtsel scalargtjoinsel ));
DATA(insert OID = 634 ( ">=" PGNSP PGUID b f 18 18 16 632 631 0 0 0 0 charge scalargtsel scalargtjoinsel )); DATA(insert OID = 634 ( ">=" PGNSP PGUID b f 18 18 16 632 631 0 0 0 0 charge scalargtsel scalargtjoinsel ));
DATA(insert OID = 635 ( "+" PGNSP PGUID b f 18 18 18 0 0 0 0 0 0 charpl - - ));
DATA(insert OID = 636 ( "-" PGNSP PGUID b f 18 18 18 0 0 0 0 0 0 charmi - - ));
DATA(insert OID = 637 ( "*" PGNSP PGUID b f 18 18 18 0 0 0 0 0 0 charmul - - ));
DATA(insert OID = 638 ( "/" PGNSP PGUID b f 18 18 18 0 0 0 0 0 0 chardiv - - ));
DATA(insert OID = 639 ( "~" PGNSP PGUID b f 19 25 16 0 640 0 0 0 0 nameregexeq regexeqsel regexeqjoinsel )); DATA(insert OID = 639 ( "~" PGNSP PGUID b f 19 25 16 0 640 0 0 0 0 nameregexeq regexeqsel regexeqjoinsel ));
#define OID_NAME_REGEXEQ_OP 639 #define OID_NAME_REGEXEQ_OP 639
DATA(insert OID = 640 ( "!~" PGNSP PGUID b f 19 25 16 0 639 0 0 0 0 nameregexne regexnesel regexnejoinsel )); DATA(insert OID = 640 ( "!~" PGNSP PGUID b f 19 25 16 0 639 0 0 0 0 nameregexne regexnesel regexnejoinsel ));
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.346 2004/10/04 22:13:14 tgl Exp $ * $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.347 2004/10/04 22:49:55 tgl Exp $
* *
* NOTES * NOTES
* The script catalog/genbki.sh reads this file and generates .bki * 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 ...@@ -181,14 +181,10 @@ DATA(insert OID = 73 ( chargt PGNSP PGUID 12 f f t f i 2 16 "18 18" _null
DESCR("greater-than"); DESCR("greater-than");
DATA(insert OID = 74 ( charge PGNSP PGUID 12 f f t f i 2 16 "18 18" _null_ charge - _null_ )); DATA(insert OID = 74 ( charge PGNSP PGUID 12 f f t f i 2 16 "18 18" _null_ charge - _null_ ));
DESCR("greater-than-or-equal"); DESCR("greater-than-or-equal");
DATA(insert OID = 1248 ( charpl PGNSP PGUID 12 f f t f i 2 18 "18 18" _null_ charpl - _null_ )); DATA(insert OID = 77 ( int4 PGNSP PGUID 12 f f t f i 1 23 "18" _null_ chartoi4 - _null_ ));
DESCR("add"); DESCR("convert char to int4");
DATA(insert OID = 1250 ( charmi PGNSP PGUID 12 f f t f i 2 18 "18 18" _null_ charmi - _null_ )); DATA(insert OID = 78 ( char PGNSP PGUID 12 f f t f i 1 18 "23" _null_ i4tochar - _null_ ));
DESCR("subtract"); DESCR("convert int4 to char");
DATA(insert OID = 77 ( charmul PGNSP PGUID 12 f f t f i 2 18 "18 18" _null_ charmul - _null_ ));
DESCR("multiply");
DATA(insert OID = 78 ( chardiv PGNSP PGUID 12 f f t f i 2 18 "18 18" _null_ chardiv - _null_ ));
DESCR("divide");
DATA(insert OID = 79 ( nameregexeq PGNSP PGUID 12 f f t f i 2 16 "19 25" _null_ nameregexeq - _null_ )); DATA(insert OID = 79 ( nameregexeq PGNSP PGUID 12 f f t f i 2 16 "19 25" _null_ nameregexeq - _null_ ));
DESCR("matches regex., case-sensitive"); DESCR("matches regex., case-sensitive");
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/utils/builtins.h,v 1.250 2004/08/30 02:54:40 momjian Exp $ * $PostgreSQL: pgsql/src/include/utils/builtins.h,v 1.251 2004/10/04 22:49:59 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -88,10 +88,8 @@ extern Datum charlt(PG_FUNCTION_ARGS); ...@@ -88,10 +88,8 @@ extern Datum charlt(PG_FUNCTION_ARGS);
extern Datum charle(PG_FUNCTION_ARGS); extern Datum charle(PG_FUNCTION_ARGS);
extern Datum chargt(PG_FUNCTION_ARGS); extern Datum chargt(PG_FUNCTION_ARGS);
extern Datum charge(PG_FUNCTION_ARGS); extern Datum charge(PG_FUNCTION_ARGS);
extern Datum charpl(PG_FUNCTION_ARGS); extern Datum chartoi4(PG_FUNCTION_ARGS);
extern Datum charmi(PG_FUNCTION_ARGS); extern Datum i4tochar(PG_FUNCTION_ARGS);
extern Datum charmul(PG_FUNCTION_ARGS);
extern Datum chardiv(PG_FUNCTION_ARGS);
extern Datum text_char(PG_FUNCTION_ARGS); extern Datum text_char(PG_FUNCTION_ARGS);
extern Datum char_text(PG_FUNCTION_ARGS); extern Datum char_text(PG_FUNCTION_ARGS);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment