Re: table function: limit, offset, order

Поиск
Список
Период
Сортировка
От Joe Conway
Тема Re: table function: limit, offset, order
Дата
Msg-id 3E7C0D3F.8050502@joeconway.com
обсуждение исходный текст
Ответ на table function: limit, offset, order  (Vadim Menshakov <vadim@price.ru>)
Ответы Re: table function: limit, offset, order
Список pgsql-general
Vadim Menshakov wrote:
>      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).

I don't think there is any way for the function to determine that there
is a limit clause. An argument is most likely your only choice. If you
are running out of function arguments, perhaps you could combine a few
related ones into an array.

> 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.

Same answer.

> 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?
>

The rows will be returned in whatever order you produce them in your
function.

The bottom line on your questions seems to be a reluctance to pass
controlling parameters in to your function. As I said above, I'd
recommend that if the number of function arguments is bumping into the
max allowed, look into using arrays to pass in parameters.

Joe


В списке pgsql-general по дате отправления:

Предыдущее
От: Martijn van Oosterhout
Дата:
Сообщение: Re: Please clarify with regard to Renaming a Sequence
Следующее
От: Martijn van Oosterhout
Дата:
Сообщение: Re: Please clarify with regard to Renaming a Sequence