SELECT: retrieve only 2 rows next to known row

From: Nikolay Samokhvalov <samokhvalov(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: SELECT: retrieve only 2 rows next to known row
Date: 2005-09-09 12:23:00
Message-ID: e431ff4c050909052360490fc2@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Bruno Wolff III 2005-09-09 12:38:30 Re: SELECT: retrieve only 2 rows next to known row
Previous Message Michael Glaesemann 2005-09-09 06:55:16 Re: a "catch all" type ... such a thing?