Re: simple division

From: Rob Sargent <robjsargent(at)gmail(dot)com>
To: Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: simple division
Date: 2018-12-05 07:07:21
Message-ID: 59110313-9F31-4D7F-BAAC-4223EE751CC7@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> On Dec 4, 2018, at 9:33 PM, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)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 following helpful:
>>>
>>>
>>> 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 one subtract the numerator from the denominator without going negative (or how many times does the numerator "go into" the denominator).
>>
>> It may seem a nuisance, but int division is a useful construct and must be supported (and be the default). (If you have 10 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))

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Rob Sargent 2018-12-05 07:18:59 Re: Moving large table between servers: logical replication or postgres_fdw
Previous Message Ron 2018-12-05 06:23:04 Re: Moving large table between servers: logical replication or postgres_fdw