numeric
CEIL / CEILING
Returns the smallest integer greater than or equal to the value — rounding always toward positive infinity. CEIL and CEILING are aliases in every major dialect.
CEIL(number) | CEILING(number) Parameters / Modifiers
| Parameter | Purpose |
|---|---|
| CEILING | Alias of CEIL, identical behavior |
| ::numeric cast | Ensure floating-point division before ceiling: CEIL(a::numeric / b) |
Examples
SELECT CEIL(3.1); Returns 4
SELECT CEIL(-3.9); Returns -3 (toward positive infinity, not away from zero)
SELECT CEIL(COUNT(*) / 10.0) FROM users; Number of pages for 10-per-page pagination
SELECT CEILING(3.0); Returns 3 — no change when already an integer
Dialect notes / Gotcha
Return type differs — Postgres returns numeric when input is numeric, MySQL returns BIGINT. Divide by a floating-point number first: CEIL(a / b) with two ints will floor the division before ceiling.
Related functions
FLOOR
Returns the largest integer less than or equal to the value — always rounds toward negative infinity. The mirror of CEIL.
ROUND
Rounds a numeric value to the specified number of decimal places (default 0). Uses banker's rounding (half-to-even) on Postgres numeric; half-away-from-zero on MySQL and float types.
AVG
Computes the arithmetic mean of non-NULL numeric values. NULL rows are excluded from both the sum and the divisor, so AVG is not equivalent to SUM/COUNT(*) when NULLs are present.
← All SQL functions · SQL cheat sheet · Window functions · PostgreSQL cheat sheet