Relational Data - Functions - Conditional Functions

From FojiSoft Docs
Revision as of 18:52, 28 August 2024 by Chris.Hansen (talk | contribs) (Import ClickHouse Docs: Wed Aug 28 2024 14:52:19 GMT-0400 (Eastern Daylight Time))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

──────────────────────────────────────────────────────────────────────────┘

:::note
The type returned is a DateTime64 as the DataTime32 must be promoted to 64 bit for the comparison.
:::

## least

Returns the least across a list of values.  All of the list members must be of comparable types.

Examples:

```sql
SELECT least(1, 2, toUInt8(3), 3.) result,  toTypeName(result) type;
┌─result─┬─type────┐
│      1 │ Float64 │
└────────┴─────────┘

The type returned is a Float64 as the UInt8 must be promoted to 64 bit for the comparison.


SELECT least(['hello'], ['there'], ['world'])
┌─least(['hello'], ['there'], ['world'])─┐
│ ['hello']                              │
└────────────────────────────────────────┘
SELECT least(toDateTime32(now() + toIntervalDay(1)), toDateTime64(now(), 3))
┌─least(toDateTime32(plus(now(), toIntervalDay(1))), toDateTime64(now(), 3))─┐
│                                                    2023-05-12 01:16:59.000 │
└────────────────────────────────────────────────────────────────────────────┘

The type returned is a DateTime64 as the DataTime32 must be promoted to 64 bit for the comparison.


clamp

Constrain the return value between A and B.

Syntax

clamp(value, min, max)

Arguments

  • value – Input value.
  • min – Limit the lower bound.
  • max – Limit the upper bound.

Returned values

If the value is less than the minimum value, return the minimum value; if it is greater than the maximum value, return the maximum value; otherwise, return the current value.

Examples:

SELECT clamp(1, 2, 3) result,  toTypeName(result) type;
┌─result─┬─type────┐
│      2 │ Float64 │
└────────┴─────────┘