Training
Module
Write queries that use window functions - Training
This content is a part of Write queries that use window functions.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
try_add
functionApplies to: Databricks SQL
Databricks Runtime 10.4 LTS and above
Returns the sum of expr1
and expr2
, or NULL in case of error.
try_add ( expr1 , expr2 )
This function can also be invoked as a window function using the OVER
clause.
expr1
: A numeric, DATE, TIMESTAMP, or INTERVAL expression.expr2
: If expr1
is a numeric expr2
must be numeric expression, or an INTERVAL otherwise.expr1
is a numeric, the common maximum type of the arguments.expr1
is a DATE and expr2
is a day-time interval the result is a TIMESTAMP.expr1
and expr2
are year-month intervals the result is a year-month interval of sufficiently wide units to represent the result.expr1
and expr2
are day-time intervals the result is a day-time interval of sufficiently wide units to represent the result.expr1
.If both expressions are interval they must be of the same class.
If the result overflows the result type Databricks SQL returns NULL.
When you add a year-month interval to a DATE Databricks SQL will assure that the resulting date is well formed.
> SELECT try_add(1, 2);
3
> SELECT try_add(DATE'2021-03-20', INTERVAL '2' MONTH);
2021-5-20
> SELECT try_add(TIMESTAMP'2021-03-20 12:15:29', INTERVAL '3' SECOND);
2021-03-20 12:15:32
> SELECT typeof(try_add(INTERVAL '3' DAY, INTERVAL '2' HOUR));
interval day to hour
> SELECT try_add(DATE'2021-03-31', INTERVAL '1' MONTH);
2021-04-30
> SELECT try_add(127Y, 1Y);
NULL
Training
Module
Write queries that use window functions - Training
This content is a part of Write queries that use window functions.