加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

PostgreSQL:float(1)和float(24)之间有什么区别?

发布时间:2020-12-13 16:06:47 所属栏目:百科 来源:网络整理
导读:我很难理解PostgreSQL中float(p)的精度参数p.例如,float(1)和float(24)似乎与我完全相同. 有谁可以向我提供一些他们的差异的例子,好吗? 解决方法 它在 the manual: PostgreSQL also supports the SQL-standard notations float and float(p) for specifyin
我很难理解PostgreSQL中float(p)的精度参数p.例如,float(1)和float(24)似乎与我完全相同.

有谁可以向我提供一些他们的差异的例子,好吗?

解决方法

它在 the manual:

PostgreSQL also supports the SQL-standard notations float and float(p)
for specifying inexact numeric types. Here,p specifies the minimum
acceptable precision in binary digits. PostgreSQL accepts float(1) to
float(24) as selecting the real type,while float(25) to float(53)
select double precision. Values of p outside the allowed range draw an
error. float with no precision specified is taken to mean double
precision.

但是,这里的关键是它指定了可接受的最低精度. PostgreSQL使用它来选择符合要求的底层数据类型(float4或float8).

regress=> x
Expanded display is on.
regress=> SELECT
        '1.123456789123456789'::float,'1.123456789123456789'::double precision,'1.123456789123456789'::float(1),'1.123456789123456789'::float(2),'1.123456789123456789'::float(24),'1.123456789123456789'::float(48);                                                                                                                                     
-[ RECORD 1 ]------------                                                                                                                                                      
float8 | 1.12345678912346
float8 | 1.12345678912346
float4 | 1.12346
float4 | 1.12346
float4 | 1.12346
float8 | 1.12345678912346

您可以使用pg_typeof确认类型选择.

实际上它只是支持标准语法,并通过选择适当的类型转换成PostgreSQL的方言 – 使用它.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读