Re: simple division - Mailing list pgsql-general

From Rob Sargent
Subject Re: simple division
Date
Msg-id 59110313-9F31-4D7F-BAAC-4223EE751CC7@gmail.com
Whole thread Raw
In response to Re: simple division  (Gavin Flower <GavinFlower@archidevsys.co.nz>)
Responses Re: simple division
List pgsql-general

> On Dec 4, 2018, at 9:33 PM, Gavin Flower <GavinFlower@archidevsys.co.nz> 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
followinghelpful: 
>>>
>>>
>>> division (integer division truncates the result)    10/3    3
>>
>> The math types might take offense here, with the use of "truncates".  Integer division really ask how many times can
onesubtract the numerator from the denominator without going negative (or how many times does the numerator "go into"
thedenominator). 
>>
>> It may seem a nuisance, but int division is a useful construct and must be supported (and be the default). (If you
have10 people to transport in cars which hold four (all can drive) 10/4 = 3 ;) ) 
>>
>>
>>
>>
> Hmm...
>
> 10 / 4 = 2
>
And two are left stranded!
 The point is that integer math has its place. You cant have 2.5 cars. So 10/4 in this context is 3.
More correctly the calculation is
10/4 + 10%4>0 ? 1 :0 = 3

(Maybe psql does have % so mod(10,4))




pgsql-general by date:

Previous
From: Ron
Date:
Subject: Re: Moving large table between servers: logical replication orpostgres_fdw
Next
From: Rob Sargent
Date:
Subject: Re: Moving large table between servers: logical replication or postgres_fdw