Re: simple division - Mailing list pgsql-general

From Gavin Flower
Subject Re: simple division
Date
Msg-id fda12258-5bac-7094-39e7-4ea55c8854fb@archidevsys.co.nz
Whole thread Raw
In response to Re: simple division  (Rob Sargent <robjsargent@gmail.com>)
Responses Re: simple division  (Geoff Winkless <pgsqladmin@geoff.dj>)
List pgsql-general
On 05/12/2018 20:07, Rob Sargent wrote:
>
>> 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
thefollowing 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
canone 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
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))
>
>
SELECT ceil(10/4.0);

Is what you want for that example.




pgsql-general by date:

Previous
From: Rob Sargent
Date:
Subject: Re: Moving large table between servers: logical replication or postgres_fdw
Next
From: Allan Kamau
Date:
Subject: Re: Geographic coordinate values format conversion to DD (DecimalDegrees) format