CEIL() Function in PostgreSQL is used to round up the value.
- Get Round up value in PostgreSQL – CEIL()
- Create the column which extracts the round up value i.e. ceiling of the column in the PostgreSQL table
Syntax for CEIL() Function in PostgreSQL:
SELECT ceil(number_or_expression);
number_or_expression: This is the number or expression for which you want to round up or find the ceiling value to it.
CEIL() Function in PostgreSQL:
CEIL() function in PostgreSQL returns the round up value, i.e. the smallest integer greater than or equal to a number
Example 1:
SELECT CEIL(4.56);
Output:
Example 2:
SELECT CEIL(-3.14);
Output:
CEIL() function (Round up value) of the column in PostgreSQL :
you can use ceil() function within a SELECT statement to calculate the smallest integer greater than or equal to each value in the column. Here’s how you can do it with the help of an example
bookkit:
Example 1:
Creating the column which extracts the round up value i.e. Ceiling of the column in the PostgreSQL table is shown
select *,CEIL(charges) as ceil_charges from bookkit
- ”CEIL(charges)” calculates the smallest integer greater than or equal to each charges.
- ”AS ceil_charges” assigns an alias ”ceil_charges” to the calculated ceiling value.
So the output will be
Output:
Round up only for the positive valued column in PostgreSQL
Example 1 – using CEIL() function:
We will be rounding up only the positive column in the example let’s take “price” column.
select *,ceil(price) as ceil_price from bookkit
Output:
Example 2 – using CAST() function:
We will be using CAST() function rounding up only the positive column in the example let’s take “price” column.
select *,cast(price as integer) as ceil_price from bookkit
The CAST function will get the smallest integer greater than or equal to each value in the column,
Note: This function is applicable only when the entire column has positive Values
Output: