SELECT: retrieve only 2 rows next to known row - Mailing list pgsql-sql

From Nikolay Samokhvalov
Subject SELECT: retrieve only 2 rows next to known row
Date
Msg-id e431ff4c050909052360490fc2@mail.gmail.com
Whole thread Raw
Responses Re: SELECT: retrieve only 2 rows next to known row
Re: SELECT: retrieve only 2 rows next to known row
Re: SELECT: retrieve only 2 rows next to known row
List pgsql-sql
Hi,

My knowledge of PostgreSQL's SQL is not good, but I know ISO/ANSI
SQL:2003 (basics) quite well.

I've encountered with following task. I have one SELECT statement with
ORDER BY clause; and know, that result set for this SELECT contains
row with ID = 1000 (just for example).
I don't know the position of this row in result set, but I want to
retrieve 2 rows that are next to this  one.

First of all, I don't want (cannot) write PL/pgSQL function.

So, I should use CREATE TEMP SEQUENCE to associate all rows in result
set with their order numbers (in MySQL. for example, I would use
temporary variable num in SELECT: something like 'select @num := @num
+ 1', but here I cannot, can't I?)

Then, as I know, PostgreSQL doesn't support standard statement WITH,
that probaby would help me with this task.

Any ways to solve this problem? Is it possible to make only one query?
(at least with one row in result set - e.g., with the row _following_
after my one)

I'd appreciate any help.

--
Best regards,
Nikolay


pgsql-sql by date:

Previous
From: Michael Glaesemann
Date:
Subject: Re: a "catch all" type ... such a thing?
Next
From: Bruno Wolff III
Date:
Subject: Re: SELECT: retrieve only 2 rows next to known row