[GRASS-dev] [GRASS GIS] #3192: add a coalesce function to r.mapcalc

#3192: add a coalesce function to r.mapcalc
-------------------------+-------------------------
Reporter: aroche | Owner: grass-dev@…
     Type: enhancement | Status: new
Priority: normal | Milestone: 7.0.6
Component: Default | Version: unspecified
Keywords: | CPU: Unspecified
Platform: Unspecified |
-------------------------+-------------------------
A ''coalesce'' function that returns the first of its non-null arguments
would be very useful: instead of using {{{if(isnull(A), x, A))}}} we could
write {{{coalesce(A, x)}}}

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3192&gt;
GRASS GIS <https://grass.osgeo.org>

#3192: add a coalesce function to r.mapcalc
-------------------------+-------------------------------------------------
  Reporter: aroche | Owner: grass-dev@…
      Type: | Status: new
  enhancement |
  Priority: normal | Milestone: 7.4.0
Component: Raster | Version: unspecified
Resolution: | Keywords: r.mapcalc, coalesce, isnull,
       CPU: | r.patch
  Unspecified | Platform: Unspecified
-------------------------+-------------------------------------------------
Changes (by wenzeslaus):

* keywords: => r.mapcalc, coalesce, isnull, r.patch
* component: Default => Raster
* milestone: 7.0.6 => 7.4.0

Comment:

Workaround: The same functionality is available through G7:r.patch.

[https://www.postgresql.org/docs/9.5/static/functions-conditional.html
PostgreSQL definition] of function ''COALESCE(value [, ...]'')

> The COALESCE function returns the first of its arguments that is not
null. Null is returned only if all arguments are null. It is often used to
substitute a default value for null values when data is retrieved for
display, for example:
>
> {{{
> SELECT COALESCE(description, short_description, '(none)') ...
> }}}
>
> This returns description if it is not null, otherwise short_description
if it is not null, otherwise (none).
>
> Like a CASE expression, COALESCE only evaluates the arguments that are
needed to determine the result; that is, arguments to the right of the
first non-null argument are not evaluated. This SQL-standard function
provides capabilities similar to NVL and IFNULL, which are used in some
other database systems.

[https://sqlite.org/lang_corefunc.html#coalesce SQLite definition] of
function ''coalesce(X,Y,...)'':

> The coalesce() function returns a copy of its first non-NULL argument,
or NULL if all arguments are NULL. Coalesce() must have at least 2
arguments.

[https://sqlite.org/lang_corefunc.html#ifnull SQLite definition] of a
similar function ''ifnull(X,Y)'':

> The ifnull() function returns a copy of its first non-NULL argument, or
NULL if both arguments are NULL. Ifnull() must have exactly 2 arguments.
The ifnull() function is equivalent to coalesce() with two arguments.

[https://sqlite.org/lang_corefunc.html#nullif SQLite definition] of a
function with a similar name ''nullif(X,Y)'':

> The nullif(X,Y) function returns its first argument if the arguments are
different and NULL if the arguments are the same.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3192#comment:1&gt;
GRASS GIS <https://grass.osgeo.org>