On Fri, 16 Jan 2004, Marco Lazzeri wrote:
> Does exist a syntax in PostgreSQL for integer (INT) number ranges?
>
> It could be useful for queries like
> "SELECT * FROM table WHERE id IN (range from 1 to 20)"
As already sent, BETWEEN will do this for you already for this kind
of use. However, if you need it for a join or something, you could
also write a set returning function that returns you the set of numbers.
Maybe something like the not really tested:
create or replace function range(int, int, int) returns setof int as '
declare
i int;
begin
i := $1;
while (i <= $2) loop
return next i;
i := i + $3;
end loop;
return;
end;' language 'plpgsql';
select * from range(1,20,1);