PostgreSQL non definisce round(double precision, integer) . Per motivi @Mike Sherrill 'Cat Recall' spiega nei commenti, la versione di round che richiede una precisione è disponibile solo per numeric .
regress=> SELECT round( float8 '3.1415927', 2 );
ERROR: function round(double precision, integer) does not exist
regress=> \df *round*
List of functions
Schema | Name | Result data type | Argument data types | Type
------------+--------+------------------+---------------------+--------
pg_catalog | dround | double precision | double precision | normal
pg_catalog | round | double precision | double precision | normal
pg_catalog | round | numeric | numeric | normal
pg_catalog | round | numeric | numeric, integer | normal
(4 rows)
regress=> SELECT round( CAST(float8 '3.1415927' as numeric), 2);
round
-------
3.14
(1 row)
(In quanto sopra, nota che float8 è solo un alias abbreviato per double precision . Puoi vedere che PostgreSQL lo sta espandendo nell'output).
Devi eseguire il cast del valore da arrotondare a numeric per usare la forma a due argomenti di round . Basta aggiungere ::numeric per il cast abbreviato, come round(val::numeric,2) .
Se stai formattando per la visualizzazione all'utente, non utilizzare round . Usa to_char (vedi:funzioni di formattazione del tipo di dati nel manuale), che ti consente di specificare un formato e ti fornisce un text risultato che non è influenzato dalle stranezze che la tua lingua client potrebbe fare con numeric valori. Ad esempio:
regress=> SELECT to_char(float8 '3.1415927', 'FM999999999.00');
to_char
---------------
3.14
(1 row)
to_char arrotonderà i numeri per te come parte della formattazione. Il FM il prefisso dice a to_char che non vuoi alcun riempimento con spazi iniziali.