agora inbox for pljava-dev@postgresql.org
help / color / mirror / Atom feed[Pljava-dev] Return a Anonymous ResultSet
3+ messages / 0 participants
[nested] [flat]
* [Pljava-dev] Return a Anonymous ResultSet
@ 2011-09-01 09:41
0 siblings, 1 reply; 3+ messages in thread
From: @ 2011-09-01 09:41 UTC (permalink / raw)
Hi
In reference to this very year old thread:
http://pgfoundry.org/pipermail/pljava-dev/2005/000277.html I have a very
similar problem and I am not sure if this problem is still remaining?
What I need is to return a result set I do not know at create time. In fact
my java code is holding a HashMap<string,object> and I need to return the
map as a table.
I thought a dummy select to return thre result will do the trick (see
this pseudo code):
PreparedStatement ps = null;
String sql = "select ";
for key in keys in map loop
sql += "? as " + key + ", ";
end loop
//expecing sql as a string like "select ? as name, ? as salary, ? as
hiredate, ? as somearray"
int i =0;
for key in keys in map loop
Object o = map.getValueOf(key);
i++;
if (o instanceof Integer) {
ps.setInt(i, (Integer) o);
} elesif ( ... ) {
do for all known types
} else {
if ( o implements serialize ) {
ps.setBytea(i, objsAsBtyea(o));
} else {
ps.setString(i, o.toString());
}
}
end loop
rs = ps.execute();
return rs; // representing the result of select * from my_java_function(with
this parameter);
But while searching for returning ResultSet examples I came across this old
thread. I am not sure if this is the best solution anyway ... what do you
think?
Thanks
Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pgfoundry.org/pipermail/pljava-dev/attachments/20110901/6406f17b/attachment.html;
^ permalink raw reply [nested|flat] 3+ messages in thread
* [Pljava-dev] Return a Anonymous ResultSet
@ 2011-09-07 22:10
parent:
0 siblings, 1 reply; 3+ messages in thread
From: @ 2011-09-07 22:10 UTC (permalink / raw)
Vorarlberger <vorarlberger at gmail.com> writes:
> Hi
> ?
> In reference to this very year old thread:
> http://pgfoundry.org/pipermail/ pljava-dev/2005/000277.html?I have a
> very similar problem?and I am not sure if
> this problem is still remaining?
> What I need is to return a result set?I do not know at create
> time. In fact my java code is holding a HashMap<string,object> and I
> need to return the map as a table.
How exactly do you define (or mean to define) the function on the sql
side?
I'm sorry if I'm misunderstanding you but it seems you're meaning to
return different data types for each row. As far as I'm aware
Postgres does not have ANYTYPE so you can't do that.
--
Johann Oskarsson http://www.2ndquadrant.com/ |[]
PostgreSQL Development, 24x7 Support, Training and Services --+--
|
Blog: http://my.opera.com/myrkraverk/blog/
^ permalink raw reply [nested|flat] 3+ messages in thread
* [Pljava-dev] Return a Anonymous ResultSet
@ 2011-09-08 11:04
parent:
0 siblings, 0 replies; 3+ messages in thread
From: @ 2011-09-08 11:04 UTC (permalink / raw)
>
> That still doesn't explain how you mean the return value to be defined
> on the SQL side. As in
>
> Ok, sorry I thougt it was clear since the subject of this thread is "Return
a Anonymous ResultSet"
> CREATE FUNCTION foo() RETURNS <say what?> AS 'Foo.foo' LANGUAGE
> JAVA;
>
CREATE FUNCTION foo() RETURNS RECORD AS 'Foo.foo' LANGUAGE
JAVA;
> If you can explain what you mean to achieve in terms of other embedded
> languages or language neutral we have a discussion. Until then I'll
> remain perplexed.
>
Her a plpgsql example
create or replace function foo()
returns record as
$$
declare
r record;
begin
-- only my java objecft do know the columns list
select 'a'::varchar(10) as a , now() as b into r;
return r;
end;
$$
language plpgsql;
select foo();
postgres=# select foo();
foo
----------------------------------
(a,"2011-09-08 12:59:34.141+02")
(1 Zeile)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pgfoundry.org/pipermail/pljava-dev/attachments/20110908/490f7f36/attachment.html;
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2011-09-08 11:04 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2011-09-01 09:41 [Pljava-dev] Return a Anonymous ResultSet
2011-09-07 22:10 `
2011-09-08 11:04 `
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox