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

Re: bytea size limit?

From: Michael Privat <michael(at)ceci(dot)mit(dot)edu>
To: Dave Cramer <pg(at)fastcrypt(dot)com>, oliver(at)opencloud(dot)com
Cc: "pgsql-jdbc(at)postgresql(dot)org" <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: bytea size limit?
Date: 2004-04-12 01:48:42
Message-ID: 1735399359.20040411214842@ceci.mit.edu (view raw or flat)
Thread:
Lists: pgsql-jdbc
Here's the full code sample for a minimalistic reproduction of the
error. When you run it, if you increase the size (through the command
line argument, you get an out of memory error. On my machine, after
the size gets higher than about 1400000 bytes. I can make it happen every
time.

The DB table has two fields:

id: integer
data: bytea


import java.sql.*;
import java.io.*;
import java.util.*;

public class BlobTest {
        public static void main(String[] args) {
                Connection c = null;
                try {
                        Class.forName("org.postgresql.Driver");
                        String url = "jdbc:postgresql://myserver/mydb";
                        c = DriverManager.getConnection(url, "myuser",
                        "mypass");

                        String sql = "INSERT INTO blobtest (id, data)
                        VALUES(?,?)";

                        int size = Integer.parseInt(args[0]);

                        byte[] data = new byte[size];

                        int id = Math.abs(new Random().nextInt());

                        PreparedStatement stmt = c.prepareStatement(sql);
                        stmt.setInt(1, id);
                        stmt.setBinaryStream(2, new ByteArrayInputStream(data), data.length);

                        stmt.executeUpdate();

                        stmt.close();
                }
                catch(Throwable t) {
                        t.printStackTrace();
                }
                finally {
                        try { c.close(); } catch(Exception e) {}
                }
        }
}



Sunday, April 11, 2004, 9:42:16 PM, you wrote:

DC> No, there is no size limit. However you may have better luck with
DC> largeobjects.
DC> Dave
DC> On Sun, 2004-04-11 at 10:57, Michael Privat wrote:
>> Hi. I have Java code that stores binary into the DB. When I use MS SQL
>> Server 2000 (type image) it works fine. But when I use Postgres 7.4 it
>> fails. Is there a size limit setting somewhere I need to set up?
>> 
>> Thanks,
>> Michael
>> 
>> 
>> ---------------------------(end of
>> broadcast)---------------------------
>> TIP 1: subscribe and unsubscribe commands go to majordomo(at)postgresql(dot)org
>> 


In response to

Responses

pgsql-jdbc by date

Next:From: Dave CramerDate: 2004-04-12 01:57:13
Subject: Re: bytea size limit?
Previous:From: Dave CramerDate: 2004-04-12 01:42:16
Subject: Re: bytea size limit?

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