Re: simple division

2018-12-05 Thread Alvaro Herrera
On 2018-Dec-06, Gavin Flower wrote: > Calculators normally work in floating point (in fact, as far as I am aware, > they never work in integer mode by default), The reason they don't work in "integer mode" is because it doesn't make sense. We only have this thing called "integer division" becaus

Re: simple division

2018-12-05 Thread Gavin Flower
On 06/12/2018 02:32, Adrian Klaver wrote: On 12/5/18 4:45 AM, Gavin Flower wrote: On 06/12/2018 00:05, Geoff Winkless wrote: On Wed, 5 Dec 2018 at 09:13, Gavin Flower wrote: SELECT ceil(10/4.0); Geoff If you divide one integer by another, then it is logical to get an integer as as the an

Re: simple division

2018-12-05 Thread Martin Mueller
I take the point that two decades of backward compatibility should and will win. That said, it's an easy enough thing to right the balance for novices and put in a really obvious place in the documentation what you should do if you want to divide two integers and get the results with the number

Re: simple division

2018-12-05 Thread Tom Lane
Geoff Winkless writes: > IMO it's fundamentally broken that SQL doesn't cast the result of a > divide into a numeric value - the potential for unexpected errors > creeping into calculations is huge; however that's the standard and > no-one's going to change it now. > Having said that it's worth no

Re: simple division

2018-12-05 Thread Raymond Brinzer
On Wed, Dec 5, 2018 at 7:55 AM Geoff Winkless wrote: > Where's the logical progression in step 3 here: > > 1 You asked the computer a question > > 2 The values you passed to it don't have decimal points > > ... > > 4 Ergo, you wanted an answer that was incorrect. > Well put. However the nature

Re: simple division

2018-12-05 Thread Adrian Klaver
On 12/5/18 4:45 AM, Gavin Flower wrote: On 06/12/2018 00:05, Geoff Winkless wrote: On Wed, 5 Dec 2018 at 09:13, Gavin Flower wrote: SELECT ceil(10/4.0); Geoff If you divide one integer by another, then it is logical to get an integer as as the answer. Hmm, grab any of my calculators and

Re: simple division

2018-12-05 Thread Geoff Winkless
On Wed, 5 Dec 2018 at 12:45, Gavin Flower wrote: > If you divide one integer by another, then it is logical to get an > integer as as the answer. Hmm. It might fit with what a computer scientist might expect (or rather, not be surprised about), but I don't think you can say that it's "logical".

Re: simple division

2018-12-05 Thread Gavin Flower
On 06/12/2018 00:05, Geoff Winkless wrote: On Wed, 5 Dec 2018 at 09:13, Gavin Flower wrote: SELECT ceil(10/4.0); Is what you want for that example. Except that implies that "number of people who can fit in a car" is a real number, not a whole. IMO it's fundamentally broken that SQL doesn't c

Re: simple division

2018-12-05 Thread Geoff Winkless
On Wed, 5 Dec 2018 at 09:13, Gavin Flower wrote: > SELECT ceil(10/4.0); > > Is what you want for that example. Except that implies that "number of people who can fit in a car" is a real number, not a whole. IMO it's fundamentally broken that SQL doesn't cast the result of a divide into a numeric

Re: simple division

2018-12-05 Thread Gavin Flower
On 05/12/2018 20:07, Rob Sargent wrote: On Dec 4, 2018, at 9:33 PM, Gavin Flower wrote: On 05/12/2018 10:51, Rob Sargent wrote: On 12/4/18 2:36 PM, Martin Mueller wrote: It worked, and I must have done something wrong. I'm probably not the only person who would find something like the fol

Re: simple division

2018-12-04 Thread Rob Sargent
> On Dec 4, 2018, at 9:33 PM, Gavin Flower > wrote: > >> On 05/12/2018 10:51, Rob Sargent wrote: >> >>> On 12/4/18 2:36 PM, Martin Mueller wrote: >>> It worked, and I must have done something wrong. I'm probably not the only >>> person who would find something like the following helpful: >>

Re: simple division

2018-12-04 Thread Gavin Flower
On 05/12/2018 10:51, Rob Sargent wrote: On 12/4/18 2:36 PM, Martin Mueller wrote: It worked, and I must have done something wrong. I'm probably not the only person who would find something like the following helpful: division (integer division truncates the result)    10/3    3 The math ty

Re: simple division

2018-12-04 Thread Rob Sargent
On 12/4/18 2:36 PM, Martin Mueller wrote: It worked, and I must have done something wrong. I'm probably not the only person who would find something like the following helpful: division (integer division truncates the result)10/33 The math types might take offense here, with th

Re: simple division

2018-12-04 Thread Thomas Kellerer
Martin Mueller schrieb am 04.12.2018 um 21:57: 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. One way is to make one

Re: simple division

2018-12-04 Thread Martin Mueller
e. If you didn't know the root form, the dictionary was no use. In this, single stop shopping for the three most common problems of simple division makes life easier for users. On 12/4/18, 3:06 PM, "David G. Johnston" wrote: On Tue, Dec 4, 2018 at 1:57 PM Martin Muell

Re: simple division

2018-12-04 Thread Albrecht Dreß
Am 04.12.18 21:57 schrieb(en) Martin Mueller: I didn't formulate my question properly, because the query went like "select alldefects /wordcount" where alldefects and wordcount are integers. test=# create table xxx(alldefects bigint, wordcount bigint); CREATE TABLE test=# insert into xxx value

Re: simple division

2018-12-04 Thread Ron
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 diffe

Re: simple division

2018-12-04 Thread David G. Johnston
On Tue, Dec 4, 2018 at 1: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. IDK...the

Re: simple division

2018-12-04 Thread Martin Mueller
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 ha

Re: simple division

2018-12-04 Thread David G. Johnston
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.

Re: simple division

2018-12-04 Thread David G. Johnston
On Tue, Dec 4, 2018 at 1: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 > d

Re: simple division

2018-12-04 Thread Thomas Kellerer
Martin Mueller schrieb am 04.12.2018 um 21:29: 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? In the expression 10/4 both numbers are integers. And an integer divsion does not yield decimals (that&#

RE: simple division

2018-12-04 Thread Igor Neyman
From: Martin Mueller Sent: Tuesday, December 4, 2018 3:30 PM To: pgsql-general Subject: simple division 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

Re: simple division

2018-12-04 Thread Joshua D. Drake
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

simple division

2018-12-04 Thread Martin Mueller
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