Forum OpenACS Development: Problem with postgres query

hi all i want to develop a bug report package.In this process i need a query to generate sequence of consecutive dates between 2 dates in a
single query?
For example......between '01-01-2003' and '01-04-2003' the result should be

01-01-2003
01-02-2003
01-03-2003
01-04-2003

I don't want to use any pgsql or any othere procedural languag. The result
should be got in a single sql statement. Like in oracle I can do it as follows by using one of my tables...

select (rownum+to_date('01-01-2000 00:00:00','mm-dd-yyyy hh24:mi:ss')) timesheetdate
from skills having (rownum+to_date('01-01-2000 00:00:00','mm-dd-yyyy hh24:mi:ss')) < to_date('01-01-2010 00:00:00','mm-dd-yyyy hh24:mi:ss')
group by rownum;

There is nothing like a rownum in postgres, so how can I do the same in postgres?

Collapse
Posted by Jade Rubick on
First of all, you might want to check out the bug-tracker package.

Can't you do the select as

select to_date(xxx) from timesheetdate where mydate between (yyy) and (zzz).

Or some syntax like that?

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);