pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Nikolay Samokhvalov <samokhvalov@gmail.com>
To: pgsql-sql@postgresql.org
Subject: SELECT: retrieve only 2 rows next to known row
Date: Fri, 9 Sep 2005 16:23:00 +0400
Message-ID: <e431ff4c050909052360490fc2@mail.gmail.com> (raw)

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



view thread (4+ messages)  latest in thread

Message-ID: <e431ff4c050909052360490fc2@mail.gmail.com>
Permalink:  ../e431ff4c050909052360490fc2@mail.gmail.com/
Also on:    postgresql.org/message-id/e431ff4c050909052360490fc2@mail.gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: samokhvalov@gmail.com
  Subject: Re: SELECT: retrieve only 2 rows next to known row
  In-Reply-To: <e431ff4c050909052360490fc2@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox