PostgreSQL

Скачать в pdf «PostgreSQL»


When using LIMIT, it is a good idea to use an ORDER BY clause that constrains the result rows into a unique order. Otherwise you will get an unpredictable subset of the query’s rows —you may be asking for the tenth through twentieth rows, but tenth through twentieth in what ordering? You don’t know what ordering, unless you specified ORDER BY.


As of Postgres 7.0, the query optimizer takes LIMIT into account when generating a query plan, so you are very likely to get different plans (yielding different row orders) depending on what you give for LIMIT and OFFSET. Thus, using different LIMIT/OFFSET values to select different subsets of a query result will give inconsistent results unless you enforce a predictable result ordering with ORDER BY. This is not a bug; it is an inherent consequence of the fact that SQL does not promise to deliver the results of a query in any particular order unless ORDER BY is used to constrain the order.


Usage


To join the table films with the table distributors:


SELECT f.title, f.did, d.name, f.date_prod, f.kind FROM distributors d, films f WHERE f.did = d.did


title    |    did    |    name    |    date_prod    |    kind


—————————+——+——————+————+———-


The Third    Man    |    101    |    British    Lion    |    1949-12-23    |    Drama


The African Queen    |    101    |    British    Lion    |    1951-08-11    |    Romantic


Une Femme est une Femme


|


102


|


Jean Luc Godard


| 1961-03-12


|


Romantic


Vertigo


|


103


|


Paramount


| 1958-11-14


|


Action


Becket


|


103


|


Paramount

Скачать в pdf «PostgreSQL»