Re: FW: [JDBC] BIGINT vs Java's long

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Dave Cramer <dave(at)fastcrypt(dot)com>
Cc: <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: FW: [JDBC] BIGINT vs Java's long
Date: 2001-08-07 19:34:02
Message-ID: Pine.LNX.4.30.0108072119080.871-100000@peter.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Dave Cramer writes:

> Apparently bigint is not really 8 bytes???

It's sort of 7.999 bytes.

> test=# update testbigint set fp0 = -9223372036854775808 where id = 1;
> ERROR: int8 value out of range: "-9223372036854775808"

This is a bug in the int8 value parser. While it reads the string it
always accumulates the value as positive and then tags the sign on.
Since +9223372036854775808 doesn't fit you get this error.

ISTM that this can be fixed by accumulating toward the negative end and
taking some special care around the boundaries, like this patch:

Index: int8.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/utils/adt/int8.c,v
retrieving revision 1.30
diff -u -r1.30 int8.c
--- int8.c 2001/06/07 00:09:29 1.30
+++ int8.c 2001/08/07 19:26:35
@@ -77,16 +77,21 @@
elog(ERROR, "Bad int8 external representation \"%s\"", str);
while (*ptr && isdigit((unsigned char) *ptr)) /* process digits */
{
- int64 newtmp = tmp * 10 + (*ptr++ - '0');
+ /* We accumulate the value towards the negative end to allow
+ the minimum value to fit it. */
+ int64 newtmp = tmp * 10 - (*ptr++ - '0');

- if ((newtmp / 10) != tmp) /* overflow? */
+ /* overflow? */
+ if ((newtmp / 10) != tmp
+ /* This number only fits with a negative sign. */
+ || (newtmp == -9223372036854775808 && sign > 0))
elog(ERROR, "int8 value out of range: \"%s\"", str);
tmp = newtmp;
}
if (*ptr) /* trailing junk? */
elog(ERROR, "Bad int8 external representation \"%s\"", str);

- result = (sign < 0) ? -tmp : tmp;
+ result = (sign > 0) ? -tmp : tmp;

PG_RETURN_INT64(result);
}
===end

--
Peter Eisentraut peter_e(at)gmx(dot)net http://funkturm.homeip.net/~peter

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Oleg Bartunov 2001-08-07 19:39:33 Re: Possible solution for LIKE optimization
Previous Message Oleg Bartunov 2001-08-07 19:33:31 Re: Re: Null-safe GiST interface (proposal)