PostgreSQL 18 reference · Math Functions
PostgreSQL CEIL() Function
Round a number up to the nearest integer: ceil(2.1) is 3 and ceil(-2.1) is -2. ceiling() is a synonym.
PostgreSQL 18
Syntax
ceil(x) | ceiling(x)
Parameters
| Parameter | Description |
|---|---|
x |
A number (integer, numeric or double precision). |
Return value
A number of the input type.
Examples
SELECT ceil(2.1) AS a, ceil(-2.1) AS b;
Output
a | b ---+---- 3 | -2 (1 row)
Run this on your computer — see “Get Started” for setup.
SELECT count(*) AS products, ceil(count(*) / 5.0) AS pages_of_5
FROM products;
Output
products | pages_of_5
----------+------------
12 | 3
(1 row)Run this on your computer — see “Get Started” for setup.
In other languages
CEIL()· SQLite
Related
FLOOR()· Round a number down to the nearest integer: floor(2.9) is 2 and floor(-2.1) is -3.ROUND()· Round a number to a given number of decimal places (0 by default). numeric rounds halves away from zero.TRUNC()· Truncate a number toward zero, optionally keeping some decimal places: trunc(2.789, 2) is 2.78.- SQL Aggregate Functions · tutorial