[Pljava-dev] Returning complex complex objects

From: yazuna at gmail(dot)com (Krzysztof)
To:
Subject: [Pljava-dev] Returning complex complex objects
Date: 2010-12-13 16:45:18
Message-ID: AANLkTik3Y1q71x+ZZF-AStOt8Au-TkdhUZKBNY7rSQp5@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pljava-dev

Hello Johann,
Certainly, the example of functionality is listed below - I was away
from any Postgres console at the time of writing and I rather meant
passing complex object to plJava, not getting from:
<sql>
-- nested, complex types handling...

create type B as ( b_val float8,b2_val int)
create type C as (c1_val float8, c2_val float8);

-- create complex, nested type
create type complexA as (
b B,
c C,
a_val int)

select ((0.1,1)::B,(0.1,0.2)::C,4)::complexA;

-- test the type
select array_agg(((0.1,i)::B,(0.1,10/i)::C,i)::complexA) from
generate_series (1,10) i;

-- is it possible to pass such complex object to java, return type is
irrelevant here..
CREATE OR REPLACE FUNCTION public.getA(complexA[])
RETURNS int varying AS
'myNestedComplexObjFunciton1'
LANGUAGE 'javau' VOLATILE;
-- then to extract all ComlpexA,B,C fields in
myNestedComplexObjFunciton at java side?
-- or vice versa: from java to SQL: fn () returns setof complexA as ... ?
-- would it be similar to _in/_out or _recv/_send functions behaviour?

select getA(array_agg(((0.1,i)::B,(0.1,10/i)::C,i)::complexA)) from
generate_series (1,10) i;

-- or is it possible to pass an object that has arrays of objects
inside? is it possible to refer to a ResultSet, with probably nested
objects/resultsets??
drop type arrayb;
create type ArrB as (barr B[], ab_val int, carr C[]);

-- test the type
select (array[(0.1,i)::B,(0.2,1+i)::B]::B[] ,i::int
,array[(0.1,10/i)::C,(10/i,i)::C]::c[] )::arrB from generate_series
(1,10) i

-- and then make even more complex argument...
CREATE OR REPLACE FUNCTION public.getArrB(arrB)
returns int
AS
'myNestedComplexObjFunciton2'
LANGUAGE 'javau' VOLATILE;

-- so the call would liook like:
select getArrB((array[(0.1,i)::B,(0.2,1+i)::B]::B[] ,i::int
,array[(0.1,10/i)::C,(10/i,i)::C]::c[] )::arrB) from generate_series
(1,10) i

-----
-- or even more convoluted example,
-- with even more complex argument:

-- test the type
select array_agg((array[(0.1,i)::B,(0.2,1+i)::B]::B[] ,i::int
,array[(0.1,10/i)::C,(10/i,i)::C]::c[] )::arrB) from generate_series
(1,10) i

CREATE OR REPLACE FUNCTION public.getArrofArrB(arrayB[])
returns int
AS
'myNestedComplexObjFunciton3'
LANGUAGE 'javau' VOLATILE;

-- so call would liook like:
select getArrofArrB(array_agg((array[(0.1,i)::B,(0.2,1+i)::B]::B[]
,i::int ,array[(0.1,10/i)::C,(10/i,i)::C]::c[] )::arrB) ) from
generate_series (1,10) i;

</sql>

Best regards,
Krzysztof

>
>> Do you know by any chance if it's possible to have nested objects
>> (within object) returned from pl/Java? Or arrays of objects as fields
>> in complex object?
>
> It is best to have concrete examples when answering these types of
> questions. ?Could you provide CREATE TYPE examples of what you have in
> mind. ?Preferably even with demonstrative functions in SQL that return
> said types.
>
>
> Johann
>

In response to

Responses

Browse pljava-dev by date

  From Date Subject
Next Message Krzysztof 2010-12-13 16:55:10 [Pljava-dev] Pljava-dev Digest, Vol 78, Issue 9
Previous Message Luca Ferrari 2010-12-13 14:59:00 [Pljava-dev] pljava @ itpug (italy) 2010