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

← All SQL functions · SQL cheat sheet · Window functions · PostgreSQL cheat sheet