Re: doubts in Illustra
Posted in 1997
Topics: Stored Procedures & SPL
Hi Uday,
udayakumar srinivasan wrote:
> I figured returning set of composite values after I posted it.
Isn't that always the way! After I posted my reply, I figured out about mi_make_composite_value. The kernel
of course provides MakeCompositeValue, which is not available for client Apps. One thing they want
to do with TimeSeries is maintain the same interface for server functions and client Apps, hence they've
introduced their own call.
> Maybe you cant return have a C aggregate function
> that returns a set of values. But the manual doesnt say so.
As I say, I got Internal Error, not a syntax error. Internal errors are Illustra's equivalent of core-dump.
I think in theory it should work; we just hit a bug.
> If you have the time, got one more question for you,
> Suppose I have a C function that returns a set of integers and I use it this
> way
>
> create function C-function(int, int)> returns setof(int)....
>
> QUERY1:
> select C-function(col1, col2)
> from table2;
>
> Is there any way I can unset(or unwind)the set it returns insert these in
> a table ?
>
Oh-Oh, you just hit the big No-No. Illustra allows sets of base types and sets of composites, but absolutely
forbids sets of sets! By default, every 'select' returns a set (so, 'select intcol from tableN' returns
setof(int) ). So QUERY1 wants to return setof(setof(int)), and - alas - there is no way to 'unwind' what is
disallowed in the first place. (The exception to default behaviour is using 'unique' if the select only
returns a single row).
As an alternative, you could write a function that takes a set and returns a set, and so handle the
'unwinding' yourself. For example, you could have :
create function NewCFunc (setof(int)) returns setof(int) ...
In NewCFunc, you iterate over the input set (using SetGetNext), process as you want, and then return a single
set. You can then call this as follows:
select * from NewCFunc( (select intcol from tbl) )
(note the doubled parentheses!)
All the best,
Rob