X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id DFB2952913 for ; Mon, 27 Jun 2005 15:41:51 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 75166-05 for ; Mon, 27 Jun 2005 18:41:50 +0000 (GMT) Received: from web11.manitu.net (web11.manitu.net [217.11.48.111]) by svr1.postgresql.org (Postfix) with ESMTP id 4ADF052823 for ; Mon, 27 Jun 2005 15:41:48 -0300 (ADT) Received: from tschibtschibojtschitsch (dsl-084-059-066-139.arcor-ip.net [84.59.66.139]) (authenticated) by web11.manitu.net (8.10.2-SOL3/8.10.2) with ESMTP id j5RIfgt12365; Mon, 27 Jun 2005 20:41:42 +0200 Subject: Re: SELECT * FROM foo OFFSET -1 LIMIT 1 From: Markus Bertheau To: =?ISO-8859-1?Q?Mart=EDn_Marqu=E9s?= Cc: pgsql-sql@postgresql.org 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> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="=-2UfomadpI5KTVRTh0P7J" Date: Mon, 27 Jun 2005 20:41:37 +0200 Message-Id: <1119897697.7464.7.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.2.1.1 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.117 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200506/320 X-Sequence-Number: 21921 --=-2UfomadpI5KTVRTh0P7J Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Dnia 27-06-2005, Mo o godzinie 14:17 -0300, Mart=C3=ADn Marqu=C3=A9s napisa= =C5=82(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 --=20 Markus Bertheau --=-2UfomadpI5KTVRTh0P7J Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.5 (GNU/Linux) iD8DBQBCwEhh2RUnMPztcykRAl+BAJ0bvx8MRKyVq1ZEOwf7Ce2gwUI24wCfU+wA 1yOuuAMEpO62Pjj5Jwl+gd4= =xZ8p -----END PGP SIGNATURE----- --=-2UfomadpI5KTVRTh0P7J--