From: | Joe Conway <mail(at)joeconway(dot)com> |
---|---|
To: | Vadim Menshakov <vadim(at)price(dot)ru> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: table function: limit, offset, order |
Date: | 2003-03-22 07:14:07 |
Message-ID: | 3E7C0D3F.8050502@joeconway.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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
From | Date | Subject | |
---|---|---|---|
Next Message | Martijn van Oosterhout | 2003-03-22 08:22:56 | Re: Please clarify with regard to Renaming a Sequence |
Previous Message | Martijn van Oosterhout | 2003-03-22 06:51:48 | Re: Please clarify with regard to Renaming a Sequence |