Re: Negative LIMIT and OFFSET? - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Negative LIMIT and OFFSET?
Date
Msg-id 26103.1197601595@sss.pgh.pa.us
Whole thread Raw
In response to Re: Negative LIMIT and OFFSET?  (Andrew Sullivan <ajs@crankycanuck.ca>)
Responses Re: Negative LIMIT and OFFSET?  ("Jonah H. Harris" <jonah.harris@gmail.com>)
Re: Negative LIMIT and OFFSET?  (Andrew Sullivan <ajs@crankycanuck.ca>)
Re: Negative LIMIT and OFFSET?  ("Merlin Moncure" <mmoncure@gmail.com>)
Re: Negative LIMIT and OFFSET?  (Neil Conway <neilc@samurai.com>)
Re: Negative LIMIT and OFFSET?  (Simon Riggs <simon@2ndquadrant.com>)
List pgsql-hackers
Andrew Sullivan <ajs@crankycanuck.ca> writes:
> On Fri, Dec 14, 2007 at 01:47:23AM +0000, Gregory Stark wrote:
>> Huh, I was all set to post an example of a useful application of it but then
>> apparently I'm wrong and it doesn't work:

> I dimly remember some discussion of this issue once before, maybe a year
> ago.  My memory isn't what it was, and I can't find it by trolling archives,
> but I recall Tom saying that it was dumb, yes, but don't do that, because
> there's some reason not to change it.  I know, helpful search terms R me.

Hmm ... I don't recall much either.  The code in nodeLimit.c just
silently replaces a negative input value by zero.  It'd certainly be
possible to make it throw an error instead, but what the downsides of
that might be aren't clear.

I guess that on purely philosophical grounds, it's not an unreasonable
behavior.  For example, "LIMIT n" means "output at most n tuples",
not "output exactly n tuples".  So when it outputs no tuples in the face
of a negative limit, it's meeting its spec.  If you want to throw an
error for negative limit, shouldn't you logically also throw an error
for limit larger than the actual number of rows produced by the subplan?
        regards, tom lane


pgsql-hackers by date:

Previous
From: "Jonah H. Harris"
Date:
Subject: Re: Negative LIMIT and OFFSET?
Next
From: Andrew Sullivan
Date:
Subject: Re: Negative LIMIT and OFFSET?