Re: Why LIMIT and OFFSET are commutative

Поиск
Список
Период
Сортировка
От Lew
Тема Re: Why LIMIT and OFFSET are commutative
Дата
Msg-id yfCdnb-Xgs_jMtTanZ2dnUVZ_gWdnZ2d@comcast.com
обсуждение исходный текст
Список pgsql-general
Andrus wrote:
> I found that
>
> SELECT * FROM foo
> ORDER BY bar
> OFFSET n
> LIMIT m
>
> and
>
> SELECT * FROM foo
> ORDER BY bar
> LIMIT m
> OFFSET n
>
> produce always same results.
>
> Why ?
> OFFSET and LIMIT operations are NOT commutative in general.

Under what interpretation would the results differ?

<http://www.postgresql.org/docs/8.2/interactive/queries-limit.html>
> If a limit count is given, no more than that many rows will be returned
> (but possibly less, if the query itself yields less rows).
...
> OFFSET says to skip that many rows before beginning to return rows.

Why would the position of either clause matter, assuming the clause is in a
legal position?

In both your examples, the LIMIT is 'm', so you will get 'm' rows.

In both your examples, the OFFSET is 'n', so you will skip 'n' rows before
returning those 'm' rows.

I see no inconsistency.

Also, neither LIMIT nor OFFSET is a binary operator, so the term "commutative"
has to be understood metaphorically at best.  What exactly do you mean by
"commutative"?

--
Lew
This post contained three requests for answers.

В списке pgsql-general по дате отправления:

Предыдущее
От: Lew
Дата:
Сообщение: Re: Error while compiling PostgreSQL with Java
Следующее
От: Lew
Дата:
Сообщение: Re: \copy ... with null as '' csv doesn't get nulls