table function: limit, offset, order - Mailing list pgsql-general

From Vadim Menshakov
Subject table function: limit, offset, order
Date
Msg-id 03032016190600.21559@geryon.com.price.ru
Whole thread Raw
Responses Re: table function: limit, offset, order  (Joe Conway <mail@joeconway.com>)
List pgsql-general
Hello,

I've got questions on the use of table functions feature in PostgreSQL 7.3.2.
I'm using FuncCallContext structure to define the maximum number of calls of
my "SRF returning a composite type":

FuncCallContext  *funcctx;
if (SRF_IS_FIRSTCALL())
{
      funcctx->max_calls = 10000;
      [.....]
}

10000 here is the maximum number of rows one can request.
When I want to select only 3 rows, I use my function My_Table_Func in the
following way:

     select * from My_Table_Func ( arg1, arg2, .... ) limit 3;

expecting the function to execute only 3 times. But it executes 10000 times
(taking lots of time), and THEN returns only 3 rows. Of course, I can pass
the limit into my function as an argument, but this will increase the number
of arguments (in fact, there's plenty of them already).
The question is, is there another way to know that the limit is exceeded ?
Another question is the same thing on OFFSET clause - is there some way to
use it inside the table function, e.g. by initializing funcctx->call_cntr to
OFFSET on the first call? I mean, except from passing it into the function as
an argument.
And the final question is about an order of rows returned by a table
function. Can it change? And if it can, in which cases it changes? Can it
change when I specify limit?




wbr Vadim Menshakov



pgsql-general by date:

Previous
From: "Frederic S"
Date:
Subject: Problems with deleting data.
Next
From: "John Duffy"
Date:
Subject: Accessing function parameters within double quotes