72 size_t *result_count) {
76 PGR_DBG(
"\nSQL QUERY: %s\n", edges_sql);
84 (*result_tuples) = NULL;
89 size_t total_edges = 0;
92 PGR_DBG(
"Total %ld edges in query:", total_edges);
94 if (total_edges == 0) {
100 PGR_DBG(
"Starting processing");
101 clock_t start_t = clock();
102 char *log_msg = NULL;
103 char *notice_msg = NULL;
104 char *err_msg = NULL;
115 time_msg(
" processing pgr_lineGraph", start_t, clock());
116 PGR_DBG(
"Returning %ld tuples", *result_count);
119 if (*result_tuples) pfree(*result_tuples);
123 if (edges) pfree(edges);
124 if (log_msg) pfree(log_msg);
125 if (notice_msg) pfree(notice_msg);
126 if (err_msg) pfree(err_msg);
134 FuncCallContext *funcctx;
135 TupleDesc tuple_desc;
141 size_t result_count = 0;
145 if (SRF_IS_FIRSTCALL()) {
146 MemoryContext oldcontext;
147 funcctx = SRF_FIRSTCALL_INIT();
148 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
161 text_to_cstring(PG_GETARG_TEXT_P(0)),
170 #if PGSQL_VERSION > 95
171 funcctx->max_calls = result_count;
173 funcctx->max_calls = (uint32_t)result_count;
175 funcctx->user_fctx = result_tuples;
176 if (get_call_result_type(fcinfo, NULL, &tuple_desc)
177 != TYPEFUNC_COMPOSITE) {
179 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
180 errmsg(
"function returning record called in context "
181 "that cannot accept type record")));
184 funcctx->tuple_desc = tuple_desc;
185 MemoryContextSwitchTo(oldcontext);
188 funcctx = SRF_PERCALL_SETUP();
189 tuple_desc = funcctx->tuple_desc;
192 if (funcctx->call_cntr < funcctx->max_calls) {
198 values = palloc(5 *
sizeof(Datum));
199 nulls = palloc(5 *
sizeof(
bool));
203 for (i = 0; i < 5; ++i) {
208 values[0] = Int32GetDatum(funcctx->call_cntr + 1);
209 values[1] = Int64GetDatum(result_tuples[funcctx->call_cntr].
source);
210 values[2] = Int64GetDatum(result_tuples[funcctx->call_cntr].
target);
211 values[3] = Float8GetDatum(result_tuples[funcctx->call_cntr].
cost);
212 values[4] = Float8GetDatum(result_tuples[
215 tuple = heap_form_tuple(tuple_desc, values, nulls);
216 result = HeapTupleGetDatum(tuple);
217 SRF_RETURN_NEXT(funcctx, result);
226 SRF_RETURN_DONE(funcctx);