Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Limit+Offset query wrong result in Postgres 9.0.3 ?

9 views
Skip to first unread message

urkpostenardr

unread,
Oct 11, 2012, 10:55:33 PM10/11/12
to
Hi,

Is this bug in Postgres ?
If yes, is it fixed in latest release ?
Second query should return 2 rows instead of 1 ?

create table t(i int);
insert into t values(1);
insert into t values(2);
insert into t values(3);
pgdb=# select i from t order by i limit 9223372036854775806 offset 1;
select i from t order by i limit 9223372036854775806 offset 1;
i
2
3
(2 rows)
pgdb=# select i from t order by i limit 9223372036854775807 offset 1;
select i from t order by i limit 9223372036854775807 offset 1;
i
2
(1 row)
pgdb=#


My server Version is postgres (PostgreSQL) 9.0.3

Thanks in advance!



Albe Laurenz

unread,
Oct 12, 2012, 5:10:40 AM10/12/12
to
That looks like a bug somewhere; at least on my 9.2.0 on Linux
I get the result that you would expect.

Which operating system and architecture is that?

Yours,
Laurenz Albe


--
Sent via pgsql-general mailing list (pgsql-...@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Alban Hertroys

unread,
Oct 12, 2012, 6:33:52 AM10/12/12
to
On 12 October 2012 04:55, urkpostenardr <urkpos...@gmail.com> wrote:
> Hi,
>
> Is this bug in Postgres ?
> If yes, is it fixed in latest release ?
> Second query should return 2 rows instead of 1 ?
>
> create table t(i int);
> insert into t values(1);
> insert into t values(2);
> insert into t values(3);
> pgdb=# select i from t order by i limit 9223372036854775806 offset 1;
> select i from t order by i limit 9223372036854775806 offset 1;
> i
> 2
> 3
> (2 rows)
> pgdb=# select i from t order by i limit 9223372036854775807 offset 1;
> select i from t order by i limit 9223372036854775807 offset 1;
> i
> 2
> (1 row)
> pgdb=#

You seem to have hit the end of a 32-bit signed integer and it wraps
around. There's probably some internal code that modifies limit-values
<1 to 1, or you wouldn't have gotten any results at all...

It does seem a fairly insane number to use for limit, it's probably
better to leave it out if you're going to accept that many results.

--
If you can't see the forest for the trees,
Cut the trees and you'll see there is no forest.

Josh Kupershmidt

unread,
Oct 12, 2012, 2:58:31 PM10/12/12
to
This was previously reported as bug #6139, and fixed in 89df948ec26679e09.

Josh
0 new messages