table function: limit, offset, order

Поиск
Список
Период
Сортировка
От Vadim Menshakov
Тема table function: limit, offset, order
Дата
Msg-id 03032016190600.21559@geryon.com.price.ru
обсуждение исходный текст
Ответы Re: table function: limit, offset, order
Список 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 по дате отправления:

Предыдущее
От: "Frederic S"
Дата:
Сообщение: Problems with deleting data.
Следующее
От: "John Duffy"
Дата:
Сообщение: Accessing function parameters within double quotes