Concept Flow - Mathematical functions (ROUND, CEIL, FLOOR, ABS)
Input Number
Apply Function Logic
Return Result Number
The input number goes through the chosen mathematical function, which processes it and returns the transformed number.
SELECT ROUND(4.7), CEIL(4.2), FLOOR(4.8), ABS(-5);
| Step | Function | Input | Operation | Result |
|---|---|---|---|---|
| 1 | ROUND | 4.7 | Round to nearest integer | 5 |
| 2 | CEIL | 4.2 | Round up to next integer | 5 |
| 3 | FLOOR | 4.8 | Round down to previous integer | 4 |
| 4 | ABS | -5 | Absolute value (remove sign) | 5 |
| 5 | END | All functions applied | Query returns (5,5,4,5) |
| Variable | Start | After Step 1 | After Step 2 | After Step 3 | After Step 4 | Final |
|---|---|---|---|---|---|---|
| ROUND_result | NULL | 5 | 5 | 5 | 5 | 5 |
| CEIL_result | NULL | NULL | 5 | 5 | 5 | 5 |
| FLOOR_result | NULL | NULL | NULL | 4 | 4 | 4 |
| ABS_result | NULL | NULL | NULL | NULL | 5 | 5 |
Mathematical functions in PostgreSQL: - ROUND(x): rounds x to nearest integer - CEIL(x): rounds x up to next integer - FLOOR(x): rounds x down to previous integer - ABS(x): returns absolute value of x Use these to transform numbers easily in queries.