Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gUHST-00033G-8d for pgsql-general@arkaria.postgresql.org; Tue, 04 Dec 2018 20:38:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gUHSR-0005Dj-UX for pgsql-general@arkaria.postgresql.org; Tue, 04 Dec 2018 20:38:15 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gUHSR-0005Bn-Kp for pgsql-general@lists.postgresql.org; Tue, 04 Dec 2018 20:38:15 +0000 Received: from lists.commandprompt.com ([69.168.55.30]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gUHSN-0002q8-0g for pgsql-general@postgresql.org; Tue, 04 Dec 2018 20:38:14 +0000 Received: from [192.168.50.9] (spinlock.commandprompt.com [69.168.55.30]) by lists.commandprompt.com (Postfix) with ESMTPA id 0DE39248; Tue, 4 Dec 2018 12:38:07 -0800 (PST) Received: from c-73-97-49-9.hsd1.wa.comcast.net ([73.97.49.9] helo=[192.168.50.9]) by assp.commandprompt.com with SMTPSA(TLSv1_2 ECDHE-RSA-AES128-GCM-SHA256) (2.5.1); 4 Dec 2018 12:38:07 -0800 Subject: Re: simple division To: Martin Mueller , pgsql-general References: <4DEACFC2-E8E3-4C61-805B-56A5F76CB819@northwestern.edu> From: "Joshua D. Drake" Organization: Command Prompt, Inc. Message-ID: Date: Tue, 4 Dec 2018 12:38:07 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <4DEACFC2-E8E3-4C61-805B-56A5F76CB819@northwestern.edu> Content-Type: multipart/alternative; boundary="------------EF9BE651DA220D904DCD6E30" Content-Language: en-US X-Assp-Version: 2.5.1(16177) on assp.commandprompt.com X-Assp-ID: assp.commandprompt.com m1-55887-00459 X-Assp-Session: 7F2830EF3E90 (mail 1) X-Assp-Original-Subject: Re: simple division X-Assp-Client-SSL: yes List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------EF9BE651DA220D904DCD6E30 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit 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. ***** --------------EF9BE651DA220D904DCD6E30 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit
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.   *****
--------------EF9BE651DA220D904DCD6E30--