From: | Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com> |
---|---|
To: | Marco Lazzeri <marco(dot)lazzeri(at)noze(dot)it> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Integer ranges in PostgreSQL |
Date: | 2004-01-19 19:27:04 |
Message-ID: | 20040119111757.Q46565@megazone.bigpanda.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
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);
From | Date | Subject | |
---|---|---|---|
Next Message | Jussi Mikkola | 2004-01-19 19:33:59 | Re: New PostgreSQL search resource |
Previous Message | Robert Treat | 2004-01-19 19:14:42 | Re: Tool to ease development of plpgsql |