我很难理解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确认类型选择.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。