On 15 Sep 2011, at 5:00pm, Sam Carleton wrote:

> I don't mean to be difficult, but I simply don't get any indication of
> how exactly COALESCE actually functions from this description:
> 
> "coalesce(X,Y,...)    The coalesce() function returns a copy of its first
> non-NULL argument, or NULL if all arguments are NULL. Coalesce() must
> be at least 2 arguments. "
> 
> I get there has to be at least two arguments, but no where do I see
> where it states it only executes an argument if all the previous one
> fail.

Fair point.

> Now it would be crystal clear if it said something like:
> 
> "coalesce(X,Y,...)    The coalesce() function returns a copy of its first
> non-NULL argument, or NULL if all arguments are NULL. Coalesce() must
> be at least 2 arguments. Coalesce() does use short-circuit
> evaluation."

That's a poor description because it relies on the reader knowing what 
'short-circuit' means.  A better one would be something like

The coalesce() function evaluates its first argument.  If the value returns is 
not NULL, that value is returned.  Otherwise it checks its next argument for 
NULL, and so on through the list in sequence.  If it runs out of arguments it 
returns NULL.  Versions before 3.6.21 evaluated all arguments first, then 
inspected the values returned.

However perhaps this suggests that you can't depend on details and should 
depend only on the value returned, not how it was arrived at.

Simon.
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to