列出postgres中的round函数:
\df round
List of functions
Schema | Name | Result data type | Argument data types | Type
------------+-------+------------------+---------------------+------
pg_catalog | round | double precision | double precision | func
pg_catalog | round | numeric | numeric | func
pg_catalog | round | numeric | numeric, integer | func
round 的参数必须是双精度、数字、整数。
select 6::float/3.3 as number;
number
--------------------
1.8181818181818183
(1 row)
如果其数据类型是双精度:
select round(6::float/3.3,4) as number;
ERROR: function round(double precision, integer) does not exist
LINE 1: select round(6::float/3.3,4) as number;
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
Time: 0.517 ms
除法的结果是哪种数据类型----
1.8181818181818183
?
pg_typeof()
检查类似内容:演示
select pg_typeof(6::float/3.3) as number_type;
数字类型 |
---|
双精度 |
它不起作用的原因是
\df
向您显示的是 不同 round()
函数,并且只有接受 numeric
的函数才具有带有第二个参数 integer
的变体,以指定如何您想要四舍五入到的许多小数位。