Forum OpenACS Q&A: Response to Postgres feature questions

Collapse
Posted by David Walker on
Depending on what you're doing with the data next it might be easier
to compute the comparison between the current row and the previous
row based on some variables you set at the end of each iteration in
your program instead of in the database.

However, if you want or need to do nearly the same thing in postgres
you do in oracle you could try using a postgres sequence to number
the rows.

create sequence test_data_view_order_seq;

create table test_data_view_order (row_num int, whatever_field
whatever_type);

insert into test_data_view_order (row_num,whatever_field)
select nextval('test_data_view_order_seq'),whatever_field
from (select id from test_data_view order by whatever_field)
whatever_alias;

Then, in your ugly query, join test_data_view_order to
test_data_view based on whatever_field where whatever_field is the
field you are ordering by.  This would be the uglier postgres hack
to replace to ugly oracle hack.