pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: 毛毛 <krave@163.com>
To: pgsql-general@lists.postgresql.org
Subject: How can I accurately infer the output of a SELECT statement FROM a table with floating-point data type?
Date: Thu, 19 Oct 2023 11:45:54 +0800 (CST)
Message-ID: <10b02a08.28b4.18b460a2f09.Coremail.krave@163.com> (raw)

Hi,


Do we have a rule by follow which one can accurately info the output of a SELECT statment FROM a table with floating-point data type?


I am working with PostgreSQL 16 and pgAdmin 7.6.


Here is my SQL script:


```

CREATE TABLE TEST (REAL_COLUMN real);

INSERT INTO TEST
VALUES (12345.123456789);

SELECT * FROM TEST;
```



I consulted the following doc and found that the range of real type is 6 decimal digits precision.
https://www.postgresql.org/docs/current/datatype-numeric.html#DATATYPE-NUMERIC



So I thought the output of the SELECT statement should be like: 12345.1 with 6 digits in total.
But it turns out to be 12345.123 with 8 digits in total.

May I know why would this happen?
Do we have a rule I can use to infer the correct output of a floating-point number without running the script?


Thank you for your time and have a great day!

view thread (5+ messages)  latest in thread

Message-ID: <10b02a08.28b4.18b460a2f09.Coremail.krave@163.com>
Permalink:  ../10b02a08.28b4.18b460a2f09.Coremail.krave@163.com/
Also on:    postgresql.org/message-id/10b02a08.28b4.18b460a2f09.Coremail.krave@163.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: krave@163.com
  Subject: Re: How can I accurately infer the output of a SELECT statement FROM a table with floating-point data type?
  In-Reply-To: <10b02a08.28b4.18b460a2f09.Coremail.krave@163.com>
  References: <10b02a08.28b4.18b460a2f09.Coremail.krave@163.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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