Rejection of the smallest int8

Поиск
Список
Период
Сортировка
От sugita@sra.co.jp
Тема Rejection of the smallest int8
Дата
Msg-id 20011121.145028.102774854.sugita@sra.co.jp
обсуждение исходный текст
Ответы Re: Rejection of the smallest int8  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-patches
Attached is a patch to accept the smallest value of int8.

The smallest value -9223372036854775808 is rejected as follows:

    test=# create table test_int8 (val int8);
    CREATE
    test=# insert into test_int8 values (-9223372036854775807);
    INSERT 4026531936 1
    test=# insert into test_int8 values (-9223372036854775808);
    ERROR:  int8 value out of range: "-9223372036854775808"
    test=#
Index: src/backend/utils/adt/int8.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/backend/utils/adt/int8.c,v
retrieving revision 1.35
diff -u -3 -p -r1.35 int8.c
--- src/backend/utils/adt/int8.c    2001/10/25 14:10:06    1.35
+++ src/backend/utils/adt/int8.c    2001/11/21 05:35:25
@@ -28,6 +28,12 @@

 #define MAXINT8LEN        25

+#ifndef INT64_MAX
+#define INT64_MAX (0x7FFFFFFFFFFFFFFFLL)
+#endif
+#ifndef INT64_MIN
+#define INT64_MIN (-INT64_MAX-1)
+#endif
 #ifndef INT_MAX
 #define INT_MAX (0x7FFFFFFFL)
 #endif
@@ -77,7 +83,7 @@ int8in(PG_FUNCTION_ARGS)
         elog(ERROR, "Bad int8 external representation \"%s\"", str);
     while (*ptr && isdigit((unsigned char) *ptr))        /* process digits */
     {
-        int64        newtmp = tmp * 10 + (*ptr++ - '0');
+        int64        newtmp = tmp * 10 - (*ptr++ - '0');

         if ((newtmp / 10) != tmp)        /* overflow? */
             elog(ERROR, "int8 value out of range: \"%s\"", str);
@@ -86,7 +92,13 @@ int8in(PG_FUNCTION_ARGS)
     if (*ptr)                    /* trailing junk? */
         elog(ERROR, "Bad int8 external representation \"%s\"", str);

-    result = (sign < 0) ? -tmp : tmp;
+    if (sign < 0) {
+        result = tmp;
+    } else {
+        if (tmp == INT64_MIN)
+            elog(ERROR, "int8 value out of range: \"%s\"", str);
+        result = -tmp;
+    }

     PG_RETURN_INT64(result);
 }

В списке pgsql-patches по дате отправления:

Предыдущее
От: Bruce Momjian
Дата:
Сообщение: Re: Chinese zh_CN NLS patches
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Rejection of the smallest int8