From: | Jon(dot)Roberts at asurion(dot)com (Roberts, Jon) |
---|---|
To: | |
Subject: | [Pljava-dev] setof record |
Date: | 2008-04-29 17:38:48 |
Message-ID: | 1A6E6D554222284AB25ABE3229A92762E9A28B@nrtexcus702.int.asurion.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pljava-dev |
Here is a sample pl/pgsql function that returns a "setof record".
create or replace function fn_test() returns setof record as
$$
declare
v_rec record;
begin
for v_rec in select cast(1 as int) as col1
union
select cast(2 as int) loop
return next v_rec;
end loop;
end;
$$
language 'plpgsql';
To use this, I would execute it as:
select * from fn_test() as (col1 int);
The trick is I must specify the columns with the appropriate data types.
I would like to take this basic concept and create a way to connect to a
remote database like Oracle or SQL Server and get data using pl/java.
The pl/java function would accept parameters like server_name, port,
user_name, password, and sql_statement and return a setof record. At
execution time, I would figure out based on the select statement I'm
passing to the function what the columns are in the remote database.
Something like:
select * from fn_remote_sql(v_server_type, v_server, v_port,
v_username, v_password,
'select name, address from customer') as
(name varchar, address varchar);
Then the next time I might execute:
select * from fn_remote_sql(v_server_type, v_server, v_port,
v_username, v_password,
'select max(id) as max_id from customer') as
(max_id integer);
So my question is, how do I return a setof record as my pl/pgsql
function does but from Java?
Jon
From | Date | Subject | |
---|---|---|---|
Next Message | Roberts, Jon | 2008-05-02 20:45:40 | [Pljava-dev] emailing with pl/java |
Previous Message | Kris Jurka | 2008-04-25 17:31:35 | [Pljava-dev] Problem PL/Java installation |