

For similar capabilities to Amazon Timestream for LiveAnalytics, consider Amazon Timestream for InfluxDB. It offers simplified data ingestion and single-digit millisecond query response times for real-time analytics. Learn more [here](https://docs.aws.amazon.com//timestream/latest/developerguide/timestream-for-influxdb.html).

# Conditional expressions
<a name="conditional-expressions"></a>

Timestream for LiveAnalytics supports the following conditional expressions.

**Topics**
+ [The CASE statement](conditional-expressions.CASE.md)
+ [The IF statement](conditional-expressions.IF.md)
+ [The COALESCE statement](conditional-expressions.COALESCE.md)
+ [The NULLIF statement](conditional-expressions.NULLIF.md)
+ [The TRY statement](conditional-expressions.TRY.md)

# The CASE statement
<a name="conditional-expressions.CASE"></a>

The **CASE** statement searches each value expression from left to right until it finds one that equals `expression`. If it finds a match, the result for the matching value is returned. If no match is found, the result from the `ELSE` clause is returned if it exists; otherwise `null` is returned. The syntax is as follows:

```
CASE expression
    WHEN value THEN result
    [ WHEN ... ]
    [ ELSE result ]
END
```

 Timestream also supports the following syntax for **CASE** statements. In this syntax, the "searched" form evaluates each boolean condition from left to right until one is `true` and returns the matching result. If no conditions are `true`, the result from the `ELSE` clause is returned if it exists; otherwise `null` is returned. See below for the alternate syntax: 

```
CASE
    WHEN condition THEN result
    [ WHEN ... ]
    [ ELSE result ]
END
```

# The IF statement
<a name="conditional-expressions.IF"></a>

The **IF** statement evaluates a condition to be true or false and returns the appropriate value. Timestream supports the following two syntax representations for **IF**:

```
if(condition, true_value)
```

This syntax evaluates and returns `true_value` if condition is `true`; otherwise `null` is returned and `true_value` is not evaluated.

```
if(condition, true_value, false_value)
```

This syntax evaluates and returns `true_value` if condition is `true`, otherwise evaluates and returns `false_value`.

## Examples
<a name="conditional-expressions.IF.examples"></a>

```
SELECT
  if(true, 'example 1'),
  if(false, 'example 2'),
  if(true, 'example 3 true', 'example 3 false'),
  if(false, 'example 4 true', 'example 4 false')
```


| \$1col0 | \$1col1 | \$1col2 | \$1col3 | 
| --- | --- | --- | --- | 
|  `example 1`  |  `-` `null`  |  `example 3 true`  |  `example 4 false`  | 

# The COALESCE statement
<a name="conditional-expressions.COALESCE"></a>

 **COALESCE** returns the first non-null value in an argument list. The syntax is as follows:

```
coalesce(value1, value2[,...])
```

# The NULLIF statement
<a name="conditional-expressions.NULLIF"></a>

The **IF** statement evaluates a condition to be true or false and returns the appropriate value. Timestream supports the following two syntax representations for **IF**:

**NULLIF** returns null if `value1` equals `value2`; otherwise it returns `value1`. The syntax is as follows:

```
nullif(value1, value2)
```

# The TRY statement
<a name="conditional-expressions.TRY"></a>

The **TRY** function evaluates an expression and handles certain types of errors by returning `null`. The syntax is as follows:

```
try(expression)
```