diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2004-10-04 22:49:59 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2004-10-04 22:49:59 +0000 |
commit | 6c61af665466131e8c96106837eaf293a472b682 (patch) | |
tree | c1c1aa0f78a78e66c3f427d5f42b3663a83c85f7 /src/backend/utils/adt/char.c | |
parent | 1ab415596d1de61561d0de8fe9da4aea207adca4 (diff) | |
download | postgresql-6c61af665466131e8c96106837eaf293a472b682.tar.gz postgresql-6c61af665466131e8c96106837eaf293a472b682.zip |
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.
Diffstat (limited to 'src/backend/utils/adt/char.c')
-rw-r--r-- | src/backend/utils/adt/char.c | 49 |
1 files changed, 20 insertions, 29 deletions
diff --git a/src/backend/utils/adt/char.c b/src/backend/utils/adt/char.c index c3ed8134d7a..1a5a70d430b 100644 --- a/src/backend/utils/adt/char.c +++ b/src/backend/utils/adt/char.c @@ -9,15 +9,25 @@ * * * 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 <limits.h> + #include "libpq/pqformat.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 * *****************************************************************************/ @@ -88,7 +98,7 @@ charsend(PG_FUNCTION_ARGS) /* * 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? */ @@ -147,45 +157,26 @@ charge(PG_FUNCTION_ARGS) 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 -charmi(PG_FUNCTION_ARGS) +chartoi4(PG_FUNCTION_ARGS) { 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 -charmul(PG_FUNCTION_ARGS) +i4tochar(PG_FUNCTION_ARGS) { - char arg1 = PG_GETARG_CHAR(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); + int32 arg1 = PG_GETARG_INT32(0); - if (arg2 == 0) + if (arg1 < SCHAR_MIN || arg1 > SCHAR_MAX) ereport(ERROR, - (errcode(ERRCODE_DIVISION_BY_ZERO), - errmsg("division by zero"))); + (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), + errmsg("\"char\" out of range"))); - PG_RETURN_CHAR((int8) arg1 / (int8) arg2); + PG_RETURN_CHAR((int8) arg1); } |