PostgreSQL CEIL() Function
The PostgreSQLCEIL() function returns a number rounded up to the next whole number.
Syntax
The following illustrates the syntax of theCEIL() function:
CEIL(numeric_expression)Arguments
TheCEIL() function requires one argument:
1)numeric_expression
Thenumeric_expression is a number (or an expression that evaluates to a number) that is rounded up.
Return Value
TheCEIL() function returns a value whose data type is the same as the input argument.
Examples
The following statement illustrates how to use theCEIL() function to round a number up to the nearest integer:
SELECT CEIL( 200.25 );The result is:
ceil------ 201(1 row)Let’s take thecustomer andpayment tables in thesample database for the demonstration.
The following example calculates the ceiling of amounts paid by customers for rentals:
SELECT first_name, last_name, CEIL(SUM( amount )) amtFROM paymentINNER JOIN customer USING(customer_id)GROUP BY customer_idORDER BY amt DESC;The following picture illustrates the result:

Remarks
To round a number down to the nearest whole number, you use theFLOOR() function.
In this tutorial, you have learned how to use the PostgreSQLCEIL() function to round a number up to the nearest integer, greater than or equal to the number.
Last updated on