CEIL

Round up to the smallest integer greater than or equal to the input.

Category: mathReturns: INTEGERDialect: Standard

Syntax

CEIL(expr)

Description

## Overview Returns the smallest integer value greater than or equal to the input. This is the mathematical ceiling function. For positive fractional inputs, CEIL rounds up to the next integer; for negative fractional inputs, it rounds toward zero (so CEIL(-4.3) is -4, not -5). CEIL is the standard primitive for billing by whole units, computing page counts, and allocating discrete resources from a continuous requirement. CEILING is a fully interchangeable alias. ## Behavior - Accepts any numeric type. For DECIMAL input, the return type is typically an integer DECIMAL with scale 0; for DOUBLE input, the return is DOUBLE. - Returns NULL if the argument is NULL. - Integer-valued inputs are returned unchanged. - For negative inputs, CEIL rounds toward zero: CEIL(-1.5) = -1, not -2. ## Numeric precision - For DECIMAL inputs, CEIL is exact. - For DOUBLE inputs, the value is subject to binary-representation rounding: CEIL(0.1) returns 1, but CEIL(0.1 + 0.2) may unexpectedly return 1 rather than 1 because 0.1 + 0.2 stored as DOUBLE is 0.30000000000000004. - Large DOUBLE magnitudes (above 2^53) are already integer-valued and are returned unchanged. ## Compatibility - Conforms to the SQL standard scalar function CEIL. CEILING is the synonym. - 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: round up a positive fraction
SELECT CEIL(4.3);
-- Result: 5
-- Negative fractional rounds toward zero
SELECT CEIL(-4.3);
-- Result: -4
-- Integer input unchanged
SELECT CEIL(7.0);
-- Result: 7
-- Very small positive value rounds up to 1
SELECT CEIL(0.1);
-- Result: 1
-- NULL propagation
SELECT CEIL(NULL);
-- Result: NULL
-- Column use: number of full pages required for N items at M per page
SELECT report_id, CEIL(item_count / 50.0) AS page_count
FROM analytics.reports.runs;

Pitfalls

See Also

Open in interactive docs →   DeltaForge home →