From: | PFC <lists(at)peufeu(dot)com> |
---|---|
To: | "Rafal Pietrak" <rafal(at)zorro(dot)isa-geek(dot)com>, pgsql-general(at)postgresql(dot)org |
Subject: | Re: a JOIN on same table, but 'slided over' |
Date: | 2007-06-26 08:17:38 |
Message-ID: | op.tuirzoemcigqcu@apollo13 |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
> 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.
From | Date | Subject | |
---|---|---|---|
Next Message | Richard Huxton | 2007-06-26 08:52:57 | Re: Duplicate records returned |
Previous Message | hubert depesz lubaczewski | 2007-06-26 08:09:09 | Re: data partitions across different nodes |