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

From Joe Conway
Subject Re: table function: limit, offset, order
Date
Msg-id 3E7C0D3F.8050502@joeconway.com
Whole thread Raw
In response to table function: limit, offset, order  (Vadim Menshakov <vadim@price.ru>)
Responses Re: table function: limit, offset, order  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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 by date:

Previous
From: Martijn van Oosterhout
Date:
Subject: Re: Please clarify with regard to Renaming a Sequence
Next
From: Martijn van Oosterhout
Date:
Subject: Re: Please clarify with regard to Renaming a Sequence