Skip to main content

Null/Zero Functions

coalesce

coalesce(val1, val2, ...)
Examples
coalesce(users.yearly_payment, users.quarterly_payment, 0)

Description

This function returns the first non-null value in a list

Return type

Vary

Sample Usages

Given an AQL expression as below:

coalesce(yearly_payment, quarterly_payment, monthly_payment)

The result would be:

NameYearly PaymentQuarterly PaymentMonthly PaymentPayment (coalesce)
Alice70.00NULLNULL70.00
BillyNULL35.00NULL35.00
ConteNULLNULL6.006.00

nullif

nullif(val1, val2)
Examples
nullif(sales_target, sales_current)

Description

This function returns NULL if two expressions are equal, otherwise it returns the first expression.

Return type

Vary

Sample Usages

Given an AQL expression as below:

nullif(sales_target, sales_current)

The result would be:

Sales PersonSales TargetSales CurrentTarget to be achieved (nullif)
Andy10,00010,000null
Billy23,00018,00023,000
Cindy21,00021,000null
Danny010,0000

safe_divide

safe_divide(dividend, divisor)
Examples
safe_divide(total_sales, count_orders)

Description

Equivalent to the division operator (X / Y), but returns NULL if divisor is 0.

Return type

Vary


Let us know what you think about this document :)