Skip to main content

ERROR_OR

Introduced or updated: v1.2.379

Returns the first non-error expression among its inputs. If all expressions result in errors, it returns NULL.

Syntax

ERROR_OR(expr1, expr2, ...)

Examples

-- Returns the valid date if no errors occur
-- Returns the current date if the conversion results in an error
SELECT NOW(), ERROR_OR('2024-12-25'::DATE, NOW()::DATE);

┌────────────────────────────────────────────────────────────────────────┐
now() │ error_or('2024-12-25'::date, now()::date)
├────────────────────────────┼───────────────────────────────────────────┤
2024-03-18 01:22:39.4603202024-12-25
└────────────────────────────────────────────────────────────────────────┘

-- Returns NULL because the conversion results in an error
SELECT ERROR_OR('2024-1234'::DATE);

┌─────────────────────────────┐
│ error_or('2024-1234'::date)
├─────────────────────────────┤
NULL
└─────────────────────────────┘
Explore Databend Cloud for FREE
Low-cost
Fast Analytics
Easy Data Ingestion
Elastic Scaling
Try it today