Re: Strange limit and offset behaviour....

From: "Adam Rich" <adam(dot)r(at)sbcglobal(dot)net>
To: 'Bjørn T Johansen' <btj(at)havleik(dot)no>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: Strange limit and offset behaviour....
Date: 2009-02-07 21:49:49
Message-ID: 0cbf01c9896e$005ecaf0$011c60d0$@r@sbcglobal.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

>
> I have the following sql:
>
> SELECT * from table order by dato asc limit 20 offset 0
>
>
> This gives me different rows than the 20 first rows when running the
> following sql:
>
> SELECT * from table order by dato asc
>
>
> Shouldn't the 20 first rows in the second sql statment be the same 20
> rows that is returned in the first statement
> or am I missing something?
>

Not necessarily. In your example query, if "dato" was not a unique
column, and there were some duplicates, the "top 20" values is not
a defined set. Adding the offset clause might cause a different
query plan, resulting in a different ordering of the duplicate values.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bjørn T Johansen 2009-02-07 21:57:19 Re: Strange limit and offset behaviour....
Previous Message Bjørn T Johansen 2009-02-07 21:29:13 Strange limit and offset behaviour....