241 FuncCallContext *funcctx;
242 TupleDesc tuple_desc;
246 size_t result_count = 0;
249 if (SRF_IS_FIRSTCALL()) {
250 MemoryContext oldcontext;
251 funcctx = SRF_FIRSTCALL_INIT();
252 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
253 if (PG_NARGS() == 7) {
264 text_to_cstring(PG_GETARG_TEXT_P(0)),
265 PG_GETARG_ARRAYTYPE_P(1),
266 PG_GETARG_ARRAYTYPE_P(2),
276 }
else if (PG_NARGS() == 5) {
285 text_to_cstring(PG_GETARG_TEXT_P(0)),
286 text_to_cstring(PG_GETARG_TEXT_P(1)),
293 }
else if (PG_NARGS() == 8) {
295 text_to_cstring(PG_GETARG_TEXT_P(0)),
296 PG_GETARG_ARRAYTYPE_P(1),
297 PG_GETARG_ARRAYTYPE_P(2),
316 text_to_cstring(PG_GETARG_TEXT_P(0)),
317 text_to_cstring(PG_GETARG_TEXT_P(1)),
327 #if PGSQL_VERSION > 95
328 funcctx->max_calls = result_count;
330 funcctx->max_calls = (uint32_t)result_count;
333 funcctx->user_fctx = result_tuples;
334 if (get_call_result_type(fcinfo, NULL, &tuple_desc)
335 != TYPEFUNC_COMPOSITE) {
337 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
338 errmsg(
"function returning record called in context "
339 "that cannot accept type record")));
342 funcctx->tuple_desc = tuple_desc;
343 MemoryContextSwitchTo(oldcontext);
346 funcctx = SRF_PERCALL_SETUP();
347 tuple_desc = funcctx->tuple_desc;
350 if (funcctx->call_cntr < funcctx->max_calls) {
355 size_t call_cntr = funcctx->call_cntr;
368 values = palloc(numb *
sizeof(Datum));
369 nulls = palloc(numb *
sizeof(
bool));
372 for (i = 0; i < numb; ++i) {
376 values[0] = Int32GetDatum(call_cntr + 1);
377 values[1] = Int32GetDatum(result_tuples[call_cntr].seq);
378 values[2] = Int64GetDatum(result_tuples[call_cntr].start_id);
379 values[3] = Int64GetDatum(result_tuples[call_cntr].end_id);
380 values[4] = Int64GetDatum(result_tuples[call_cntr].node);
381 values[5] = Int64GetDatum(result_tuples[call_cntr].
edge);
382 values[6] = Float8GetDatum(result_tuples[call_cntr].cost);
383 values[7] = Float8GetDatum(result_tuples[call_cntr].agg_cost);
386 tuple = heap_form_tuple(tuple_desc, values, nulls);
387 result = HeapTupleGetDatum(tuple);
388 SRF_RETURN_NEXT(funcctx, result);
390 SRF_RETURN_DONE(funcctx);