pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Markus Bertheau <twanger@bluetwanger.de>
To: Martín Marqués <martin@bugs.unl.edu.ar>
Cc: pgsql-sql@postgresql.org
Subject: Re: SELECT * FROM foo OFFSET -1 LIMIT 1
Date: Mon, 27 Jun 2005 20:41:37 +0200
Message-ID: <1119897697.7464.7.camel@localhost.localdomain> (raw)
In-Reply-To: <200506271417.28851.martin@bugs.unl.edu.ar>
References: <1119886449.29687.3.camel@dicaprio.akademie1.de>
	<200506271417.28851.martin@bugs.unl.edu.ar>

Dnia 27-06-2005, Mo o godzinie 14:17 -0300, Martín Marqués napisał(a):

> How do you skip -1 rows?

You redefine OFFSET to mean "where in the result set to start returning
rows" and give -1 the meaning that I described above.

Please don't ask me, where in the result set position -1 is.


I've stumbled over this because I needed a query which given an id a
result set like this:

id txt pos
23 foo 0
11 bar 1
34 baz 2
13 xop 3

returns the previous and next rows relative to the given id, as ordered
by the position). That would be 23 and 34 for 11, or NULL and 11 for 23.
I'm basically determining the position of the middle row and then
querying with offset pos-1 limit 1 and offset pos+1 limit 1.

Offset for negative numbers means 0, as it seems. I think there is a
sensible meaning for negative offset numbers and wondered, what
arguments led to negative offsets being processed as 0 offset.

Markus

-- 
Markus Bertheau <twanger@bluetwanger.de>

Attachments:

  signature.asc (application/pgp-signature, 188B) download

view thread (4+ messages)  latest in thread

Message-ID: <1119897697.7464.7.camel@localhost.localdomain>
Permalink:  ../1119897697.7464.7.camel@localhost.localdomain/
Also on:    postgresql.org/message-id/1119897697.7464.7.camel@localhost.localdomain

 · 

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: twanger@bluetwanger.de, martin@bugs.unl.edu.ar
  Subject: Re: SELECT * FROM foo OFFSET -1 LIMIT 1
  In-Reply-To: <1119897697.7464.7.camel@localhost.localdomain>

* 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