Accessing elements of bytea[] always returns NULL

From: "Sestak, John S" <John(dot)Sestak(at)ManTech(dot)com>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: Accessing elements of bytea[] always returns NULL
Date: 2008-10-01 15:06:21
Message-ID: 9E8ED72A78F2A541AD26902A549A13E20193A0A4@fchsmamb01.ManTech.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi all,
I'm trying to pass in a bytea array (i.e. bytea[]) into my stored
procedure but when I try to access the elements in the array using an
array index it always returns NULL. In other words, if I do the
following:

CREATE OR REPLACE FUNCTION some_function( _test BYTEA[] )
RETURNS BIGINT AS
$BODY$
DECLARE
some_var BYTEA;
BEGIN

some_var := _test[1];

RETURN 0;

END;

...

The variable 'some_var' is always NULL. Technically '_test' is a
one-dimensional array so I would think this would work but it doesn't.
So, how do you access the bytea elements of a bytea array? I'm pretty
sure the elements of the array have data in them because when I call
array_dims() it returns the correct dimensions for the array that has
been passed in.

Could it be the JDBC code? Here's how I'm passing the bytea array data
in:

public static void addHashes(Connection connection) throws SQLException
{
CallableStatement cs = null;

try {
cs = connection.prepareCall("{ ? = call some_function(?) }");

cs.registerOutParameter(1, Types.BIGINT);

// Initialize with some data
byte[][] hashes = new byte[2][2];
hashes[0][0] = 1;
hashes[0][1] = 2;
hashes[1][0] = 3;
hashes[1][1] = 4;

java.sql.Array byte_array = connection.createArrayOf("bytea", hashes);
cs.setArray(2, byte_array);

cs.execute();
}
catch( Exception e)
{
log.error("Error: Caught exception - " + e.getMessage());
}
finally
{
if (cs != null)
{
cs.close()
}
}
}

Thank you,
John

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2008-10-01 15:47:16 Re: Accessing elements of bytea[] always returns NULL
Previous Message Scott Marlowe 2008-10-01 02:30:47 Re: Can COPY update or skip existing records?