Variable LIMIT and OFFSET in SELECTs - Mailing list pgsql-general

From Reg Me Please
Subject Variable LIMIT and OFFSET in SELECTs
Date
Msg-id 200711150221.08096.regmeplease@gmail.com
Whole thread Raw
Responses Re: Variable LIMIT and OFFSET in SELECTs  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: Variable LIMIT and OFFSET in SELECTs  (Gregory Stark <stark@enterprisedb.com>)
List pgsql-general
Hi all.

I'd need to implement a "parametric windowed select" over a table
called "atable". The idea is to have a one row table to maintain
the LIMIT and the OFFSET for the selects. If I try this:

create table limoff( l int, o int );
insert into limoff values ( 10,2 );
select a.* from atable a,limoff limit l offset o;

I get "ERROR:  argument of OFFSET must not contain variables".
(You get the error also on LIMIT if you put a constant as the offset).

But I can do the following:

create or replace function f_limoff_1( l int, o int )
returns setof atable as $$
select * from atable limit $1 offset $2
$$ language sql;

create or replace function f_limoff()
returns setof atable as $$
select * from f_limoff_1( (select l from limoff),(select i from limoff) );
$$ language sql;

Of course, in my opinion at least, there's no real reason for the above
syntax limitation, as the sematics is not.

Wouldn't it be a nice enhacement to allow variable LIMIT and OFFSET in
SELECTs?

--
Reg me Please

pgsql-general by date:

Previous
From: "Merlin Moncure"
Date:
Subject: Re: Path to top of tree
Next
From: Alvaro Herrera
Date:
Subject: Re: stripping HTML, SQL injections ...