Opened 3 years ago

Last modified 10 months 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 Changed 2 years ago by wenzeslaus

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 Changed 2 years ago by neteler

Milestone: 7.4.07.4.1

Ticket retargeted after milestone closed

comment:3 Changed 20 months ago by neteler

Milestone: 7.4.17.4.2

comment:4 Changed 16 months ago by martinl

Milestone: 7.4.27.6.0

All enhancement tickets should be assigned to 7.6 milestone.

comment:5 Changed 12 months ago by martinl

Milestone: 7.6.07.6.1

Ticket retargeted after milestone closed

comment:6 Changed 10 months ago by martinl

Milestone: 7.6.17.6.2

Ticket retargeted after milestone closed

Note: See TracTickets for help on using tickets.