47 size_t *result_count) {
48 PGR_DBG(
"\nSQL QUERY: %s\n", edges_sql);
52 (*result_tuples) = NULL;
57 size_t total_edges = 0;
60 PGR_DBG(
"Total %ld edges in query:", total_edges);
62 if (total_edges == 0) {
69 clock_t start_t = clock();
71 char *notice_msg = NULL;
82 time_msg(
" processing pgr_lineGraphFull", start_t, clock());
83 PGR_DBG(
"Returning %ld tuples", *result_count);
86 if (*result_tuples) pfree(*result_tuples);
91 if (edges) pfree(edges);
92 if (log_msg) pfree(log_msg);
93 if (notice_msg) pfree(notice_msg);
94 if (err_msg) pfree(err_msg);
102 FuncCallContext *funcctx;
103 TupleDesc tuple_desc;
106 size_t result_count = 0;
108 if (SRF_IS_FIRSTCALL()) {
109 MemoryContext oldcontext;
110 funcctx = SRF_FIRSTCALL_INIT();
111 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
114 process(text_to_cstring(PG_GETARG_TEXT_P(0)),
118 #if PGSQL_VERSION > 95
119 funcctx->max_calls = result_count;
121 funcctx->max_calls = (uint32_t)result_count;
123 funcctx->user_fctx = result_tuples;
124 if (get_call_result_type(fcinfo, NULL, &tuple_desc)
125 != TYPEFUNC_COMPOSITE) {
127 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
128 errmsg(
"function returning record called in context "
129 "that cannot accept type record")));
132 funcctx->tuple_desc = tuple_desc;
133 MemoryContextSwitchTo(oldcontext);
136 funcctx = SRF_PERCALL_SETUP();
137 tuple_desc = funcctx->tuple_desc;
140 if (funcctx->call_cntr < funcctx->max_calls) {
146 values = palloc(5 *
sizeof(Datum));
147 nulls = palloc(5 *
sizeof(
bool));
151 for (i = 0; i < 5; ++i) {
155 size_t c_cntr = funcctx->call_cntr;
157 values[0] = Int32GetDatum(c_cntr + 1);
158 values[1] = Int64GetDatum(result_tuples[c_cntr].source);
159 values[2] = Int64GetDatum(result_tuples[c_cntr].target);
160 values[3] = Float8GetDatum(result_tuples[c_cntr].cost);
161 values[4] = Int64GetDatum(result_tuples[c_cntr].
edge);
163 tuple = heap_form_tuple(tuple_desc, values, nulls);
164 result = HeapTupleGetDatum(tuple);
165 SRF_RETURN_NEXT(funcctx, result);
168 SRF_RETURN_DONE(funcctx);