CEILING

Round up to the smallest integer greater than or equal to the input (alias for CEIL).

Category: mathReturns: INTEGERDialect: Standard

Syntax

CEILING(expr)

Description

## Overview Returns the smallest integer value greater than or equal to the input. CEILING is the SQL-standard long-form spelling. CEIL is the shorthand alias. The two are fully interchangeable and share every behavior and pitfall. Use CEILING when targeting the SQL standard spelling or when the verbose form reads better in documentation; CEIL is more common in ad-hoc queries. ## Behavior - Accepts any numeric type. - Returns NULL if the argument is NULL. - Integer-valued inputs are returned unchanged. - For negative inputs, CEILING rounds toward zero: CEILING(-1.5) = -1, not -2. ## Numeric precision - For DECIMAL inputs, CEILING is exact. - For DOUBLE inputs, the value is subject to binary-representation rounding. - Large DOUBLE magnitudes (above 2^53) are returned unchanged because they are already integer-valued. ## Compatibility - CEILING is the SQL standard spelling; CEIL is the short alias supported by most engines. - Matches typical mathematical library implementations.

Parameters

NameTypeDescription
exprSpecifies the numeric value to round up. Accepts any numeric type. Returns the smallest integer-valued number that is greater than or equal to the input.

Examples

-- Basic literal
SELECT CEILING(4.3);
-- Result: 5
-- Negative fractional rounds toward zero
SELECT CEILING(-4.3);
-- Result: -4
-- Zero is unchanged
SELECT CEILING(0.0);
-- Result: 0
-- Used inside an expression
SELECT CEILING(9.99) * 2;
-- Result: 20
-- NULL propagation
SELECT CEILING(NULL);
-- Result: NULL
-- Column use: pricing tiers for consumption-based billing
SELECT account_id, CEILING(usage_gb) AS billable_gb
FROM billing.invoices.line_items;

Pitfalls

See Also

Open in interactive docs →   DeltaForge home →