Skip site navigation (1) Skip section navigation (2)

BIGINT vs Java's long

From: Dav Coleman <dav(at)danger-island(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: BIGINT vs Java's long
Date: 2001-08-07 15:37:21
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-jdbc
According to the Java Language Specification,

"For long, from -9223372036854775808 to 9223372036854775807, inclusive"

Indeed, I have java code which generate random long's and println's them,
and I end up with values equal to -9223372036854775808.

I had those println's redirected to a .sql file which I ran against
psql to update some bigint columns, but I got 
    ERROR:  int8 value out of range: "-9223372036854775808"

Apparently bigint's don't like that value?

Well confused, since 8 bytes should be 8 freaking bytes, I turned to JDBC.

That's when things got weird, first I tried declaring a long variable with
that value, and got a compilere error (Integer to large) or something like

So I declared "long myBigint = Long.MIN_VALUE" and that compiled, but when
I tried using that value in a Statement.execute() I got the exact same

Anyone know what's going on? Here's the test code, using jdbc7.0-1.2.jar:

import java.sql.*;

public class testPGSQLbigint {

    public static void main( String[] args ) {
       try {
       } catch (java.lang.ClassNotFoundException e) {
            System.out.println( e );

       Connection db=null;
       String url = "jdbc:postgresql:abinitio2";
       try {
            db = DriverManager.getConnection(url,"dav","");
       } catch ( SQLException e ) {
            System.err.println( e );

       // the following gives a compiler error
       //long bigint = -9223372036854775808;
       long bigint = Long.MIN_VALUE;
       String sql_ = "update chembase set fp0 = "+bigint+" where id =

       try {
            Statement st = db.createStatement();
            st.execute( sql_ );
       } catch ( SQLException e ) {
            System.err.println( e );


$ java -classpath /opt/java/jars/jdbc7.0-1.2.jar:. "testPGSQLbigint"

update chembase set fp0 = -9223372036854775808 where id = 27948;
java.sql.SQLException: ERROR:  int8 value out of range: "-9223372036854775808"

note this runs the same in linux and win2k (using Sun's SDK)

Dav Coleman


pgsql-jdbc by date

Next:From: Steve WamplerDate: 2001-08-07 15:37:26
Subject: Re: Bug found in the driver
Previous:From: Bryan Field-ElliotDate: 2001-08-07 14:27:43
Subject: PG Point and Circle data types, and JDBC?

Privacy Policy | About PostgreSQL
Copyright © 1996-2018 The PostgreSQL Global Development Group