Forum OpenACS Development: Re: Problem with postgres query

Collapse
Posted by David Walker on
PostgreSQL 8.0 has the generate_series function. You can create a generate_series function in earlier versions of postgresql that would function the same and work in your query.

-- Use in Postgres 7.4.x and earlier.
-- In Postgres 8.0.0 generate_series() is a built-in function
CREATE OR REPLACE FUNCTION generate_series(int, int) RETURNS setof int AS '
BEGIN
FOR i IN $1..$2 LOOP
RETURN NEXT i;
END LOOP;
RETURN;
END;
' LANGUAGE plpgsql;

and a sample query
select CURRENT_TIMESTAMP + (s.a::text || ' days')::interval from generate_series(1,4) as s(a);