Re: How to force select to return exactly one row - Mailing list pgsql-general

From Tim Landscheidt
Subject Re: How to force select to return exactly one row
Date
Msg-id m3bpb33oks.fsf@passepartout.tim-landscheidt.de
Whole thread Raw
In response to How to force select to return exactly one row  ("Andrus" <kobruleht2@hot.ee>)
List pgsql-general
Brett Mc Bride <brett.mcbride@deakin.edu.au> wrote:

> My understanding of UNION ALL is that it won't sort the rows...?
> [...]

It doesn't, but that's not promised for every data set, ev-
ery PostgreSQL version, every phase of the moon. To quote
<URI:http://www.postgresql.org/docs/8.4/interactive/queries-union.html>:

| UNION effectively appends the result of query2 to the result
| of query1 (although there is no guarantee that this is the
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| order in which the rows are actually returned). Furthermore,
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| it eliminates duplicate rows from its result, in the same
| way as DISTINCT, unless UNION ALL is used.

SQL deals with (unordered) sets, and therefore any use of
"LIMIT" without "ORDER BY" indicates a bug waiting to bite
you when you least expect it.

Tim

pgsql-general by date:

Previous
From: Brett Mc Bride
Date:
Subject: Re: How to force select to return exactly one row
Next
From: Phil Jackson
Date:
Subject: Trying to install ODBC driver on Windows XP notebook