On Tue, 19 Jun 2001, Tom Lane wrote:

> Peter Eisentraut <[EMAIL PROTECTED]> writes:
> > Sure, you create a (static) global variable and reallocate memory for it
> > in each call and free it by the finalizer function.
> 
> A static would be a bad idea (consider a query with multiple instances
> of this aggregate being evaluated in parallel).
> 
> But there's no reason that the transition function can't palloc a larger
> and larger chunk of memory for each result (as long as you don't run out
> of memory, anyway).
> 
>                       regards, tom lane
> 

I'm still a bit confused about how to declare the type of the transition state.
I have a structure that will hold the current state:
struct state {
        int elem_count; //how many numbers have been assigned so far
        int *elem_area; //ptr to area holding these integers whose median I'll later 
calculate
}

So the transition function is:
struct state *trans_function(struct state *last_state,int new_element){
        //Allocate mem for a new state structure to hold all previous numbers + new one
        //Copy over all the previous elements from last_state and add the new_element
        //Return ptr to this new state struct
}

My question is: how do I declare this in Pg?
declare function transition_func(???,int4) RETURNS ??? AS 
'path_to_.so_file','trans_function' LANGUAGE 'C';

I assume that I have mixed up what can be a transition state :-/

Any help welcome.


TIA,
thalis


---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to [EMAIL PROTECTED] so that your
message can get through to the mailing list cleanly

Reply via email to