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 1gUHvq-0004RP-GE for pgsql-general@arkaria.postgresql.org; Tue, 04 Dec 2018 21:08:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gUHvp-0006hl-6f for pgsql-general@arkaria.postgresql.org; Tue, 04 Dec 2018 21:08:37 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gUHvo-0006he-RN for pgsql-general@lists.postgresql.org; Tue, 04 Dec 2018 21:08:36 +0000 Received: from mail-ot1-x331.google.com ([2607:f8b0:4864:20::331]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gUHvm-0000fK-Az for pgsql-general@lists.postgresql.org; Tue, 04 Dec 2018 21:08:35 +0000 Received: by mail-ot1-x331.google.com with SMTP id n8so12720380otl.6 for ; Tue, 04 Dec 2018 13:08:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=6kLMYW67CG2dre5VHHCfrdfHEq1a+KRJehDliDoAczs=; b=bp8uqfZwBhd8Olszhu9SPkvHsq2xg+QtvAdoNEQUccVTHoMN912RJbffm2LyMiMrtl 2RqTdv5MVww47+gnsqpq0JUaxPleylAGyM4NUDMouFLFhr4r0yTRQCvfd6L/VwWPXIg9 7cAArnceL2lnfj6LS9TSjsLoby988B6HeGvfVK1+6qObG55MpzQJVcRs2ZPT6vvnNNlG f1UDjX5uNlETfKm90c7gdEETqNYtFQwmq5iPF9RmnL7rgNRnL0nZfsUFsqI3cXGNAA7S mAuQiBl6IDh0reD0GG5z/xurt/U1a/LrutEoZRV5Em2ofLwO0/hc1tzbmPtlV7+Mlp/3 Y24g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=6kLMYW67CG2dre5VHHCfrdfHEq1a+KRJehDliDoAczs=; b=eWhWq4Uxs++7WAhXs79RbW9cQCidWUnQo+/t3yPcRC4pxJVU0dWgnMOEnYHYDI0qp1 aO6ZWx0Il/UWwkZVQMfDXHRzS5ZcuOBRGKREea7xMJTGyFRe5qTV02kkM7SD7hj2SNMi JjKMJKXzLJnbD8Fs3nnu8WZhwXH3iZ3vQty+QIH91G/tefTjFAeBsqAbpayIHEQY6HkS gRJTREN9HmXoqCV3lpNjeYACOvWyw7iwvMOz2ydFwirZUX9LRHCE7dSzUdv8xe4gDE+9 DfgeUonXErauwrEHdm5pvrlwbtrT1c1+G98WcmEPV/K49BvgIK8IeS22rR+7jslgHMs9 cN2g== X-Gm-Message-State: AA+aEWarpjPvGD5zsGAMrZ7Rs+chHuo8cogcMNNYlG4KDFr1L4T1WmDJ euuXX/mPSLgc1P6Jd4EKkKhOL5Kh X-Google-Smtp-Source: AFSGD/WpCYqirfL3zZEHjnT/emVLEWh8iSlKHQQpuiNTJ+7mxO9XVZYNF44BV4WdrKWeI4NUBDXyZQ== X-Received: by 2002:a9d:5183:: with SMTP id y3mr12613015otg.5.1543957712930; Tue, 04 Dec 2018 13:08:32 -0800 (PST) Received: from [192.168.1.10] (ip70-171-116-89.no.no.cox.net. [70.171.116.89]) by smtp.googlemail.com with ESMTPSA id q25sm9503349otg.70.2018.12.04.13.08.31 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Dec 2018 13:08:31 -0800 (PST) Subject: Re: simple division To: pgsql-general@lists.postgresql.org References: <4DEACFC2-E8E3-4C61-805B-56A5F76CB819@northwestern.edu> <8B35EF9C-8DEF-4298-A646-89D1AC8F63E1@northwestern.edu> From: Ron Message-ID: <640d078c-e132-3e51-a1bb-df0b29d8a09c@gmail.com> Date: Tue, 4 Dec 2018 15:08:30 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <8B35EF9C-8DEF-4298-A646-89D1AC8F63E1@northwestern.edu> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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" wrote: > > On Tue, Dec 4, 2018 at 1:38 PM Joshua D. Drake 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.