sql - My PostgreSQL calculations don't include decimals -
i don't dabble in sql queries , rely on google when need more basics, , have come problem.
i trying calculate value , returns result rounded down nearest integer.
to test out, wrote following query:
select elaptime "elapsec", elaptime/60 "elapmin" cmr_runinf the result is:
+-----------+-----------+ |elapsec |elapmin | +-----------+-----------+ |258 |4 | +-----------+-----------+ |0 |0 | +-----------+-----------+ |2128 |35 | +-----------+-----------+ |59 |0 | +-----------+-----------+ i'm trying bit more this, i've simplified make easier explain problem. how ensure calculation returns decimal point?
your sql product performs integral division because both operands integers. elaptime's integer type determined table structure , 60 automatically assumed integer because has no decimal point.
there 2 methods of resolving issue:
convert either operand non-integer numeric type explicitly:
cast(elaptime float) / 60write
60.0instead of60parser can see not dividing integer integer:elaptime / 60.0
Comments
Post a Comment