Database Reference
In-Depth Information
Finally, we return the tuple using macro SRF_RETURN_NEXT(...) , converting the
tuple to Datum, as this is what the macro expects.
One more thing to note, all current versions of PostgreSQL will always keep calling
your function until it returns SRF_RETURN_DONE() . There is currently no way to do
an "early exit" from the callers side. This means that if your function returns 1 million
rows and you do.
select * from mymillionrowfunction() limit 3;
The function will get called 1 million times internally, and all the results will be cached,
and only after this the first 3 rows will be returned and the remaining 999,997 rows
are discarded. This is not a fundamental limitation, but just an implementation de-
tail which is likely to change in some future version of PostgreSQL. Don't hold your
breath though, this will only happen if somebody finds this valuable enough to imple-
ment.
The source with modifications described previously are as follows:
struct c_reverse_tuple_args {
int32 argvals[3];
bool argnulls[3];
bool anyargnull;
};
Datum
c_permutations_x(PG_FUNCTION_ARGS)
{
FuncCallContext *funcctx;
const char *argnames[3] = {"a","b","c"};
// 6 possible index permutations for 0,1,2
const int ips[6][3] = {{0,1,2},{0,2,1},
{1,0,2},{1,2,0},
{2,0,1},{2,1,0}};
int i, call_nr;
Search WWH ::




Custom Search