List the round function in postgres:
\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
The argument for round must be double precision,numeric,integer.
select 6::float/3.3 as number;
number
--------------------
1.8181818181818183
(1 row)
If its data type is double precision :
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
Which data type is the result of division----1.8181818181818183?
You can always check things like that with
pg_typeof(): demoThe reason your function call didn't work is that
\dfshowed you three differentround()functions. The first two accept exactly one argument:and only the one accepting
numerichas a variant with a 2nd argument,integer, to specify how many decimal places you want to round to.So if you cast to
::numericinstead or don't cast at all and let PostgreSQL presumenumericby default, you can get that one to get picked:Here's the doc on result types in mixed-type mathematical operations:
The list in question being "
smallint,integer,bigint,numeric,real, anddouble precision". Here's a cheatsheet: