From: Joshua D. Drake <jd@commandprompt.com>
To: Martin Mueller <martinmueller@northwestern.edu>
To: pgsql-general <pgsql-general@postgresql.org>
Subject: Re: simple division
Date: Tue, 4 Dec 2018 12:38:07 -0800
Message-ID: <dd63a926-6711-b795-6485-5029b9556213@commandprompt.com> (raw)
In-Reply-To: <4DEACFC2-E8E3-4C61-805B-56A5F76CB819@northwestern.edu>
References: <4DEACFC2-E8E3-4C61-805B-56A5F76CB819@northwestern.edu>
On 12/4/18 12:29 PM, Martin Mueller wrote:
>
> I have asked this question before and apologize for not remembering
> it. How do you do simple division in postgres and get 10/4 with decimals?
>
> This involves cast and numeric in odd ways that are not well explained
> in the documentation. For instance, you’d expect an example in the
> Mathematical Functions. But there isn’t.
>
> The documentation of string functions is exemplary. The documentation
> of mathematical less so. Remember that it may be used by folks like me
> whose math is shaky. The MySQL documentation is better on this simple
> operation.
>
I may be misunderstanding the question but:
select cast(x/y as numeric(10,4));
JD
> -----
>
> Martin Mueller
> Professor emeritus of English and Classics
>
> Northwestern University
>
--
Command Prompt, Inc. || http://the.postgres.company/ || @cmdpromptinc
*** A fault and talent of mine is to tell it exactly how it is. ***
PostgreSQL centered full stack support, consulting and development.
Advocate: @amplifypostgres || Learn: https://postgresconf.org
***** Unless otherwise stated, opinions are my own. *****
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: jd@commandprompt.com, martinmueller@northwestern.edu
Subject: Re: simple division
In-Reply-To: <dd63a926-6711-b795-6485-5029b9556213@commandprompt.com>
References: <4DEACFC2-E8E3-4C61-805B-56A5F76CB819@northwestern.edu> <dd63a926-6711-b795-6485-5029b9556213@commandprompt.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