Thread: problem with plpgsql

problem with plpgsql

From
Pavel Stehule
Date:
Hello

In my code I evaluate expr
select array(select generate_series from generate_series(1,800)

my code       var = (PLpgSQL_var *) (estate->datums[stmt->varno]);       value = exec_eval_expr(estate, stmt->expr,
&isnull,&valtype);       exec_eval_cleanup(estate);
 


and iteration over array
ndim = ARR_NDIM(value);dims = ARR_DIMS(value);nitems = ArrayGetNItems(ndim, dims);
 element_type = ARR_ELEMTYPE(value); p = ARR_DATA_PTR(value);
 get_typlenbyvalalign(element_type, &typlen, &typbyval, &typalign);
 for (i = 0; i < nitems; i++) // tak aby to zvladalo dimenze {        Datum           itemvalue;
       itemvalue = fetch_att(p, typbyval, typlen);       exec_assign_value(estate, (PLpgSQL_datum *) var,
itemvalue,element_type, &isnull);
 
               p = att_addlength(p, typlen, PointerGetDatum(p));               p = (char *) att_align(p, typalign);

works fine, but from random index > 300 array is broken

NOTICE:  400
NOTICE:  401
NOTICE:  402
NOTICE:  403
NOTICE:  404
NOTICE:  405
NOTICE:  406
NOTICE:  407
NOTICE:  408
NOTICE:  409
NOTICE:  410
NOTICE:  411
NOTICE:  412
NOTICE:  413
NOTICE:  414
NOTICE:  415
NOTICE:  157207208
NOTICE:  16
NOTICE:  3486004
NOTICE:  419
NOTICE:  420
NOTICE:  421
NOTICE:  157207208
NOTICE:  16

Can you help me, what I do wrong?

Thank You
Pavel Stehule



Re: problem with plpgsql

From
Tom Lane
Date:
Pavel Stehule <stehule@kix.fsv.cvut.cz> writes:
> Hello
> In my code I evaluate expr

>  select array(select generate_series from generate_series(1,800)

> my code
>         var = (PLpgSQL_var *) (estate->datums[stmt->varno]);
>         value = exec_eval_expr(estate, stmt->expr, &isnull, &valtype);
>         exec_eval_cleanup(estate);

> and iteration over array

Uh, once you've done the exec_eval_cleanup, you can't use the result of 
exec_eval_expr anymore.

Do I guess correctly that you're trying to do backend development
without having configured --enable-cassert?  Bad idea.
        regards, tom lane