Re: coalesce function - Mailing list pgsql-general

From David Johnston
Subject Re: coalesce function
Date
Msg-id 1371828055818-5760342.post@n5.nabble.com
Whole thread Raw
In response to Re: coalesce function  (Chris Angelico <rosuav@gmail.com>)
List pgsql-general
Chris Angelico wrote
> On Fri, Jun 21, 2013 at 7:36 AM, David Johnston <

> polobo@

> > wrote:
>>         SELECT input
>>         FROM ( SELECT unnest($1) AS input ) src
>>         WHERE input IS NOT NULL AND input <> ''
>>         LIMIT 1;
>
> Does this guarantee the order of the results returned? Using LIMIT
> without ORDER BY is something I've learned to avoid.
>
> ChrisA

I have thought about this and while I'm not 100% positive on the guarantee
the fact the input data is small means the planner should not be re-ordering
"src" in order to apply the where clause (if it would anyway...I think
re-ordering may only happen during joins).  To my knowledge the result of
unnest returns in the same order as the array so "src" already has an
implicit "ORDER BY" attached to it.  It is only when return physical
relation data is the order undefined.  Arrays and "VALUES" both are returned
in the order defined.

David J.





--
View this message in context: http://postgresql.1045698.n5.nabble.com/coalesce-function-tp5760161p5760342.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


pgsql-general by date:

Previous
From: David Johnston
Date:
Subject: Re: Circular references
Next
From: Alan Nilsson
Date:
Subject: Re: variadic args to C functions