pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Fwd: error in the example given for numeric data types
6+ messages / 5 participants
[nested] [flat]

* Fwd: error in the example given for numeric data types
@ 2023-07-15 06:38  Priyank Rajvansh <rajvansh.priyank@gmail.com>
  0 siblings, 2 replies; 6+ messages in thread

From: Priyank Rajvansh @ 2023-07-15 06:38 UTC (permalink / raw)
  To: pgsql-general

Respected postgresql team,forwarded email.

Thank You

Kindly have a look at the
---------- Forwarded message ---------
From: PG Doc comments form <noreply@postgresql.org>
Date: Sat, Jan 28, 2023 at 11:22 AM
Subject: error in the example given for numeric data types
To: <pgsql-docs@lists.postgresql.org>
Cc: <rajvansh.priyank@gmail.com>


The following documentation comment has been logged on the website:

Page: https://www.postgresql.org/docs/15/datatype-numeric.html
Description:

article 8.1.2 states the following:

''We use the following terms below: The precision of a numeric is the total
count of significant digits in the whole number, that is, the number of
digits to both sides of the decimal point. The scale of a numeric is the
count of decimal digits in the fractional part, to the right of the decimal
point. So the number 23.5141 has a precision of 6 and a scale of 4. Integers
can be considered to have a scale of zero.''

however it also states the following towards the end:

'' For example, a column declared as

NUMERIC(3, 5)
will round values to 5 decimal places and can store values between -0.00999
and 0.00999, inclusive.''

Now from whatever i could decipher the syntax of the numeric data type is
NUMERIC(precision,scale) and if we write NUMERIC (3,5) it would mean that we
are trying to store a number which has 3 digits in total and 5 of them are
to the right of the decimal point, which doesn't make sense !
besides i tried running this in postgresql and the result was as follows:

practice=# create table t1(height numeric(3,5));
ERROR:  NUMERIC scale 5 must be between 0 and precision 3
LINE 1: create table t1(height numeric(3,5));
 Please look into the matter and kindly revert back to me whatever you find
out about this so that i can correct myself incase i misunderstood what the
document says...

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: error in the example given for numeric data types
@ 2023-07-15 07:16  jian he <jian.universality@gmail.com>
  parent: Priyank Rajvansh <rajvansh.priyank@gmail.com>
  1 sibling, 2 replies; 6+ messages in thread

From: jian he @ 2023-07-15 07:16 UTC (permalink / raw)
  To: Priyank Rajvansh <rajvansh.priyank@gmail.com>; +Cc: pgsql-general

> Page: https://www.postgresql.org/docs/15/datatype-numeric.html

"docs/15" means this url pointer to pg version 15.

> practice=# create table t1(height numeric(3,5));
> ERROR:  NUMERIC scale 5 must be between 0 and precision 3
> LINE 1: create table t1(height numeric(3,5));
>  Please look into the matter and kindly revert back to me whatever you find
> out about this so that i can correct myself incase i misunderstood what the
> document says...

it works in pg15, not in pg14.
see my test: https://dbfiddle.uk/wgfjCx7j





^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: error in the example given for numeric data types
@ 2023-07-15 13:16  Tom Lane <tgl@sss.pgh.pa.us>
  parent: jian he <jian.universality@gmail.com>
  1 sibling, 0 replies; 6+ messages in thread

From: Tom Lane @ 2023-07-15 13:16 UTC (permalink / raw)
  To: jian he <jian.universality@gmail.com>; +Cc: Priyank Rajvansh <rajvansh.priyank@gmail.com>; pgsql-general

jian he <jian.universality@gmail.com> writes:
>> practice=# create table t1(height numeric(3,5));
>> ERROR:  NUMERIC scale 5 must be between 0 and precision 3

> it works in pg15, not in pg14.
> see my test: https://dbfiddle.uk/wgfjCx7j

Indeed. The quoted documentation text is different between v15 and prior
versions.  Observe also the v15 release notes:

https://www.postgresql.org/docs/15/release-15.html

    E.4.3.4. Data Types

        Allow the scale of a numeric value to be negative, or greater than
        its precision (Dean Rasheed, Tom Lane)

        This allows rounding of values to the left of the decimal point,
        e.g., '1234'::numeric(4, -2) returns 1200.


			regards, tom lane





^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: error in the example given for numeric data types
@ 2023-07-15 17:50  Priyank Rajvansh <rajvansh.priyank@gmail.com>
  parent: jian he <jian.universality@gmail.com>
  1 sibling, 1 reply; 6+ messages in thread

From: Priyank Rajvansh @ 2023-07-15 17:50 UTC (permalink / raw)
  To: jian he <jian.universality@gmail.com>; +Cc: pgsql-general

First of all thanks for your reply.This mean that this was a bug in the
previous versions right?
Secondly, I would love to connect with you as I am a college student and I
want to be a contributor to open source software so can we connect on some
platform? I really need someone to guide me

Thanking you in advance,
Priyank Rajvansh

On Sat, 15 Jul, 2023, 12:46 pm jian he, <jian.universality@gmail.com> wrote:

> > Page: https://www.postgresql.org/docs/15/datatype-numeric.html
>
> "docs/15" means this url pointer to pg version 15.
>
> > practice=# create table t1(height numeric(3,5));
> > ERROR:  NUMERIC scale 5 must be between 0 and precision 3
> > LINE 1: create table t1(height numeric(3,5));
> >  Please look into the matter and kindly revert back to me whatever you
> find
> > out about this so that i can correct myself incase i misunderstood what
> the
> > document says...
>
> it works in pg15, not in pg14.
> see my test: https://dbfiddle.uk/wgfjCx7j
>

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: error in the example given for numeric data types
@ 2023-07-15 18:09  David G. Johnston <david.g.johnston@gmail.com>
  parent: Priyank Rajvansh <rajvansh.priyank@gmail.com>
  0 siblings, 0 replies; 6+ messages in thread

From: David G. Johnston @ 2023-07-15 18:09 UTC (permalink / raw)
  To: Priyank Rajvansh <rajvansh.priyank@gmail.com>; +Cc: jian he <jian.universality@gmail.com>; pgsql-general

On Sat, Jul 15, 2023 at 10:50 AM Priyank Rajvansh <
rajvansh.priyank@gmail.com> wrote:

>
> First of all thanks for your reply.This mean that this was a bug in the
> previous versions right?
>

No, it means that a prior version limitation has been lifted, so a
definition that was previously undefined is now defined.  It is not a bug
to choose to not implement something.

David J.

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Fwd: error in the example given for numeric data types
@ 2023-07-15 21:19  Peter J. Holzer <hjp-pgsql@hjp.at>
  parent: Priyank Rajvansh <rajvansh.priyank@gmail.com>
  1 sibling, 0 replies; 6+ messages in thread

From: Peter J. Holzer @ 2023-07-15 21:19 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

On 2023-07-15 12:08:26 +0530, Priyank Rajvansh wrote:
> Page: https://www.postgresql.org/docs/15/datatype-numeric.html
> Description:
> 
> article 8.1.2 states the following:
> 
> ''We use the following terms below: The precision of a numeric is the total
> count of significant digits in the whole number, that is, the number of
> digits to both sides of the decimal point. The scale of a numeric is the
> count of decimal digits in the fractional part, to the right of the decimal
> point. So the number 23.5141 has a precision of 6 and a scale of 4. Integers
> can be considered to have a scale of zero.''
> 
> however it also states the following towards the end:
> 
> '' For example, a column declared as
> 
> NUMERIC(3, 5)
> will round values to 5 decimal places and can store values between -0.00999
> and 0.00999, inclusive.''
> 
> Now from whatever i could decipher the syntax of the numeric data type is
> NUMERIC(precision,scale) and if we write NUMERIC (3,5) it would mean that we
> are trying to store a number which has 3 digits in total and 5 of them are
> to the right of the decimal point, which doesn't make sense !

It may sound weird but it does make sense. There are three digits in the
number and the rightmost of them is five positions to the right of the
decimal pointis. So you can store

    0.00999
    --12345

but not

    0.01000
    --12345

as that would need a fourth digit
and also not
    0.000123
    --123456
as not the rightmost digit is now six places right of the decimal
point.

Mathematically you store an integer with 3 digits and multiply it with
10^-5 to get the value.

        hp

-- 
   _  | Peter J. Holzer    | Story must make more sense than reality.
|_|_) |                    |
| |   | hjp@hjp.at         |    -- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |       challenge!"

Attachments:

  signature.asc (application/pgp-signature, 832B) download

^ permalink  raw  reply  [nested|flat] 6+ messages in thread


end of thread, other threads:[~2023-07-15 21:19 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-07-15 06:38 Fwd: error in the example given for numeric data types Priyank Rajvansh <rajvansh.priyank@gmail.com>
2023-07-15 07:16 ` jian he <jian.universality@gmail.com>
2023-07-15 13:16   ` Tom Lane <tgl@sss.pgh.pa.us>
2023-07-15 17:50   ` Priyank Rajvansh <rajvansh.priyank@gmail.com>
2023-07-15 18:09     ` David G. Johnston <david.g.johnston@gmail.com>
2023-07-15 21:19 ` Peter J. Holzer <hjp-pgsql@hjp.at>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox