Re: simple division

From: Martin Mueller <martinmueller(at)northwestern(dot)edu>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: simple division
Date: 2018-12-04 21:36:35
Message-ID: 1F5FCEFC-7DEA-46FA-9895-FBF7DFDEC750@northwestern.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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
division (with decimal results) 10/3::numeric 3.3333
division (rounded) round(10/3::numeric, 2) 3.33

From an end user's the question "how do I divide two integers and limit the number of decimals" is surely a common one. And if you look it up somewhere, division is probably the search word. Now you could argue that the user should already know about formatting and rounding. But some don't.

If you wanted to look up a rare wordform in a famous early 20th century dictionary of Old English, you had to know the root form of the word. If you already knew the root form, there is a good chance that you didn't need to look it up in the first place. 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" <david(dot)g(dot)johnston(at)gmail(dot)com> wrote:

On Tue, Dec 4, 2018 at 1:57 PM Martin Mueller
<martinmueller(at)northwestern(dot)edu> 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 first thing that came to mind was to just stick it at the
end of the expression:

select x/y::numeric from (values (10,4)) vals (x,y)

And it worked...

If you want to propose a concrete documentation patch more power to
you but this doesn't come up enough to think that what we have is
materially deficient. I'm sorry you are having trouble with it but
the lists do provide quick and customized answers for situations like
this.

David J.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Thomas Kellerer 2018-12-04 21:38:48 Re: simple division
Previous Message Albrecht Dreß 2018-12-04 21:09:04 Re: simple division