Opened 7 years ago

Last modified 5 years ago

#3192 new enhancement

add a coalesce function to r.mapcalc

Reported by: aroche Owned by: grass-dev@…
Priority: normal Milestone: 7.6.2
Component: Raster Version: unspecified
Keywords: r.mapcalc, coalesce, isnull, r.patch Cc:
CPU: Unspecified Platform: Unspecified

Description

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)

Change History (6)

comment:1 by wenzeslaus, 7 years ago

Component: DefaultRaster
Keywords: r.mapcalc coalesce isnull r.patch added
Milestone: 7.0.67.4.0

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

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.

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.

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.

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.

comment:2 by neteler, 6 years ago

Milestone: 7.4.07.4.1

Ticket retargeted after milestone closed

comment:3 by neteler, 6 years ago

Milestone: 7.4.17.4.2

comment:4 by martinl, 6 years ago

Milestone: 7.4.27.6.0

All enhancement tickets should be assigned to 7.6 milestone.

comment:5 by martinl, 5 years ago

Milestone: 7.6.07.6.1

Ticket retargeted after milestone closed

comment:6 by martinl, 5 years ago

Milestone: 7.6.17.6.2

Ticket retargeted after milestone closed

Note: See TracTickets for help on using tickets.