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

Reply via email to