Tuesday, June 30, 2020

PostgreSQL: ROUND makes the value 0.5 returned from a calculation to 0 instead of 1 - Solved

In PostgreSQL, things can look odd as the following queries show.

postgres=> select round(3/cast(6 as float));
 round
-------
     0
postgres=> select 3/cast(6 as float);
 ?column?
----------
      0.5
postgres=> select round(0.5);
 round
-------
     1

To make round(3/cast(6 as float)) to return 1 instead of 0, you need to put another layer of parenthesis to it.

postgres=> select round((3/cast(6 as numeric)));
 round
-------
     1

-----------------------------------------------------------------------------------------------------------------
Watch the blessing and loving online channel: SupremeMasterTV live




If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book for free here.

No comments:

Post a Comment