Re: simple division

From: Ron <ronljohnsonjr(at)gmail(dot)com>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: simple division
Date: 2018-12-04 21:08:30
Message-ID: 640d078c-e132-3e51-a1bb-df0b29d8a09c@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Use CAST() instead of ::.

SELECT CAST(alldefects AS NUMEREIC(10,4))/wordcount;

On 12/04/2018 02:57 PM, Martin Mueller wrote:
> I didn't formulate my question properly, because the query went like
> "select alldefects /wordcount"
> where alldefects and wordcount are integers. But none of the different ways of putting the double colon seemed to work.
>
> The Postgres notation of this simple procedure is very unintuitive. I haven't been able to remember several times, and most people think of me as a person with a reasonably good memory. There is no obvious place in the documentation to look this up.
>
>
> On 12/4/18, 2:45 PM, "David G. Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> wrote:
>
> On Tue, Dec 4, 2018 at 1:38 PM Joshua D. Drake <jd(at)commandprompt(dot)com> wrote:
> > I may be misunderstanding the question but:
> Indeed...
> > select cast(x/y as numeric(10,4));
>
> Your answer is 2.0 instead of the correct 2.5 - you need to cast
> before the division, not after.
>
> David J.
>
>

--
Angular momentum makes the world go 'round.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Albrecht Dreß 2018-12-04 21:09:04 Re: simple division
Previous Message David G. Johnston 2018-12-04 21:06:29 Re: simple division