Accessing elements of bytea[] always returns NULL - Mailing list pgsql-sql

From Sestak, John S
Subject Accessing elements of bytea[] always returns NULL
Date
Msg-id 9E8ED72A78F2A541AD26902A549A13E20193A0A4@fchsmamb01.ManTech.com
Whole thread Raw
Responses Re: Accessing elements of bytea[] always returns NULL  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-sql
<div class="Section1"><p class="MsoNormal"><font face="Times New Roman" size="3"><span style="font-size:
12.0pt">Hi all,<br /> I'm trying to pass in a bytea array (i.e. bytea[]) into my stored procedure but when I try to
accessthe elements in the array using an array index it always returns NULL. In other words, if I do the following:<br
/><br/> CREATE OR REPLACE FUNCTION some_function( _test BYTEA[] )<br /> RETURNS BIGINT AS<br /> $BODY$<br /> DECLARE<br
/>some_var BYTEA;<br /> BEGIN<br /><br /> some_var := _test[1];<br /><br /> RETURN 0;<br /><br /> END;<br /><br />
...<br/><br /> The variable 'some_var' is always NULL. Technically '_test' is a one-dimensional array so I would think
thiswould work but it doesn't. So, how do you access the bytea elements of a bytea array? I'm pretty sure the elements
ofthe array have data in them because when I call array_dims() it returns the correct dimensions for the array that has
beenpassed in.<br /><br /></span></font><p class="MsoNormal"><font face="Times New Roman" size="3"><span
style="font-size:
12.0pt"> </span></font><p class="MsoNormal"><font face="Times New Roman" size="3"><span style="font-size:
12.0pt">Could it be the JDBC code?  Here’s how I’m passing the bytea array data in:</span></font><p
class="MsoNormal"><fontface="Times New Roman" size="3"><span style="font-size: 
12.0pt"> </span></font><p class="MsoNormal"><font face="Times New Roman" size="3"><span lang="EN-GB"
style="font-size:12.0pt">publicstatic void addHashes(Connection connection) throws SQLException<br /> {<br />
CallableStatementcs = null;<br /><br /> try {<br /> cs = connection.prepareCall("{ ? = call some_function(?) }");<br
/><br/> cs.registerOutParameter(1, Types.BIGINT);<br /><br /> // Initialize with some data<br /> byte[][] hashes = new
byte[2][2];<br/> hashes[0][0] = 1;<br /> hashes[0][1] = 2;<br /> hashes[1][0] = 3;<br /> hashes[1][1] = 4;<br /><br />
java.sql.Arraybyte_array = connection.createArrayOf("bytea", hashes);<br /> cs.setArray(2, byte_array);<br /><br />
cs.execute();<br/> }<br /> catch( Exception e)<br /> {<br /> log.error("Error: Caught exception - " +
e.getMessage());<br/> }<br /> finally<br /> {<br /> if (cs != null)<br /> {<br /> cs.close()<br /> }<br /> }<br />
}</span></font><pclass="MsoNormal"><font face="Times New Roman" size="3"><span style="font-size: 
12.0pt"><br /> Thank you,<br /> John</span></font><font face="Arial" size="2"><span style="font-size:10.0pt;
font-family:Arial"></span></font></div>

pgsql-sql by date:

Previous
From: "Scott Marlowe"
Date:
Subject: Re: Can COPY update or skip existing records?
Next
From: Tom Lane
Date:
Subject: Re: Accessing elements of bytea[] always returns NULL