pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ron <ronljohnsonjr@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: simple division
Date: Tue, 4 Dec 2018 15:08:30 -0600
Message-ID: <640d078c-e132-3e51-a1bb-df0b29d8a09c@gmail.com> (raw)
In-Reply-To: <8B35EF9C-8DEF-4298-A646-89D1AC8F63E1@northwestern.edu>
References: <4DEACFC2-E8E3-4C61-805B-56A5F76CB819@northwestern.edu>
	<dd63a926-6711-b795-6485-5029b9556213@commandprompt.com>
	<CAKFQuwZXO4WJqEbmWUtnCvDhRfVqYWbFx7bQ8D-Q-mxPRqEKgg@mail.gmail.com>
	<8B35EF9C-8DEF-4298-A646-89D1AC8F63E1@northwestern.edu>

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.g.johnston@gmail.com> wrote:
>
>      On Tue, Dec 4, 2018 at 1:38 PM Joshua D. Drake <jd@commandprompt.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.




view thread (25+ messages)  latest in thread

Message-ID: <640d078c-e132-3e51-a1bb-df0b29d8a09c@gmail.com>
Permalink:  ../640d078c-e132-3e51-a1bb-df0b29d8a09c@gmail.com/
Also on:    postgresql.org/message-id/640d078c-e132-3e51-a1bb-df0b29d8a09c@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: ronljohnsonjr@gmail.com
  Subject: Re: simple division
  In-Reply-To: <640d078c-e132-3e51-a1bb-df0b29d8a09c@gmail.com>
  References: <4DEACFC2-E8E3-4C61-805B-56A5F76CB819@northwestern.edu> <dd63a926-6711-b795-6485-5029b9556213@commandprompt.com> <CAKFQuwZXO4WJqEbmWUtnCvDhRfVqYWbFx7bQ8D-Q-mxPRqEKgg@mail.gmail.com> <8B35EF9C-8DEF-4298-A646-89D1AC8F63E1@northwestern.edu> <640d078c-e132-3e51-a1bb-df0b29d8a09c@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox