Обсуждение: how to pass an array to the plpgsql function from Java Code

Поиск
Список
Период
Сортировка

how to pass an array to the plpgsql function from Java Code

От
"Sandeep Kumar Jakkaraju"
Дата:
how to pass an array to the plpgsql function from Java Code ??
say from a JDBC preparedStatement ....
 
 
Example :-
 
create or replace function test( x integer[] ) returns integer as
$BODY$
BEGIN
RETURN x[0];
END ;
language 'plpgsql'
 
JDBC CODE :-
 
 
int [] ar = {1,2,3};
 
PreparedStament pre= connection.prepareStatement( " select test(?) ");
 
pre.setArray(1,ar};
 
 

Re: how to pass an array to the plpgsql function from Java Code

От
"ksherlock@gmail.com"
Дата:
On Mar 4, 11:34 am, sandeepkumar.jakkar...@gmail.com ("Sandeep Kumar
Jakkaraju") wrote:
> how to pass an array to the plpgsql function from Java Code ??

If nothing else, you could use the ARRAY[] constructor:

int [] ar = {1,2,3};
PreparedStament pre= connection.prepareStatement( " select
test(ARRAY[?,?,?]) ");

pre.setArray(1,ar[0]);
pre.setArray(2,ar[1]);
pre.setArray(3,ar[2]);