Now, I'd like to make a JOIN-ed query of that table with itself, so that I'd get rows paiwise: every row containing data from *two* rows of the original TEST table so, that those data come from rows of consequtive ID's - not neceserly (depending on the TEST table contents) continuesly consequtive. Like: SELECT * from view_of_test; id | id+X | thread | thread+X | info | info+X ----+------+--------+----------+-------+--------- 2 | 3 | 763 | 764 | A | B 3 | 6 | 764 | 5 | B | C 6 | 8 | 5 | 88946 | C | Cats 8 | 9 | 88946 | 69315 | Cats | Eifel 9 | 10 | 69315 | 96379 | Eifel | G ------------------------------------------------- Is there an SQL construct to get it?
I would use a plpgsql procedure, select all the rows ORDER BY id, keep the current and last row in a variable, and that's it.