Wait... what? We got a 0? After being taught it's 0.25? Has someone deceived us?
What happened here is called integer division. This occurs when both the dividend and the divisor are integers. Since they are integers, PostgreSQL wants to return an integer result to match the operand types. In other words, it brutally cuts off the decimal part, which is
.25 in our case. The zero (
0) is the only thing left.
So, how can we make sure that the result includes the decimal part? One way is to change the type of one of the values to a decimal (e.g.,
1 / 4.0 instead of
1 / 4). In this course, we will always change the type of the denominator.