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:

  1. convert either operand non-integer numeric type explicitly:

    cast(elaptime float) / 60 
  2. write 60.0 instead of 60 parser can see not dividing integer integer:

    elaptime / 60.0 

Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -