Re: a JOIN on same table, but 'slided over' - Mailing list pgsql-general

From PFC
Subject Re: a JOIN on same table, but 'slided over'
Date
Msg-id op.tuirzoemcigqcu@apollo13
Whole thread Raw
In response to a JOIN on same table, but 'slided over'  (Rafal Pietrak <rafal@zorro.isa-geek.com>)
List 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.

pgsql-general by date:

Previous
From: "hubert depesz lubaczewski"
Date:
Subject: Re: data partitions across different nodes
Next
From: Richard Huxton
Date:
Subject: Re: Duplicate records returned