From: | Itai <itaid(at)outlook(dot)com> |
---|---|
To: | Andres Freund <andres(at)2ndquadrant(dot)com> |
Cc: | "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Crash on SRF execution |
Date: | 2015-03-15 15:59:39 |
Message-ID: | DUB127-W889F0723FFE7BFE5E48EE8AD050@phx.gbl |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Thanks for the quick response!! :)
But I don't get it... isn't:
if (SRF_IS_FIRSTCALL()){
}
the iterator one time
"initialization block" where I setup the data to be iterated
upon?
Can you please elaborate on how should I fix this? I'm probably missing something basic...
> Date: Sun, 15 Mar 2015 16:50:27 +0100
> From: andres(at)2ndquadrant(dot)com
> To: itaid(at)outlook(dot)com
> CC: pgsql-hackers(at)postgresql(dot)org
> Subject: Re: [HACKERS] Crash on SRF execution
>
> Hi,
>
> On 2015-03-15 17:40:11 +0200, Itai wrote:
> > I'm attempting to program a simple SRF function but it constantly crashes (details and code below).
> >
> > Any idea why?
>
> > if (SRF_IS_FIRSTCALL())
> > {
> > length = 4000;
> > base_num = 1203000000;
> > list = (NumberList *)palloc(sizeof(NumberList));
> > list->pp_numbers = (Number **)palloc(sizeof(Number*) * length);
> > list->length = length;
> > i = 0;
> > for (; i < length; i++)
> > {
> > num = (Number *)palloc(sizeof(Number));
> > num->value = base_num + i;
> > num->is_even = ((base_num + i) % 2 == 0) ? 1 : 0;
> > list->pp_numbers[i] = num;
> > }
> > ereport(INFO, (errmsg("----------- data source -----------")));
> > i = 0;
> > for (; i < length; i++)
> > {
> > ereport(INFO, (errmsg("value: %d", list->pp_numbers[i]->value)));
> > ereport(INFO, (errmsg("is_even: %d", list->pp_numbers[i]->is_even)));
> > }
> >
> > funcctx = SRF_FIRSTCALL_INIT();
> > oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
> > funcctx->user_fctx = list;
> > funcctx->max_calls = list->length;
> > if (get_call_result_type(fcinfo, NULL, &funcctx->tuple_desc) != TYPEFUNC_COMPOSITE)
> > ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
> > errmsg("check if sql function definition returns SETOF record")));
> >
> > BlessTupleDesc(funcctx->tuple_desc);
> > MemoryContextSwitchTo(oldcontext);
> > }
>
> The palloc() for list above is in the per call memory context, but you
> use it across several calls. You should allocate it in the multi call
> context you use some lines below.
>
> Greetings,
>
> Andres Freund
>
> --
> Andres Freund http://www.2ndQuadrant.com/
> PostgreSQL Development, 24x7 Support, Training & Services
>
>
> --
> Sent via pgsql-hackers mailing list (pgsql-hackers(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-hackers
From | Date | Subject | |
---|---|---|---|
Next Message | Andres Freund | 2015-03-15 16:03:38 | Re: Crash on SRF execution |
Previous Message | Magnus Hagander | 2015-03-15 15:54:10 | Re: recovery_target_action = pause & hot_standby = off |