
Use to_char (see: data type formatting functions in the manual), which lets you specify a format and gives you a text result that isn't affected by whatever weirdness your client language might do with numeric values. If you're formatting for display to the user, don't use round. Just append ::numeric for the shorthand cast, like round(val::numeric,2). You must cast the value to be rounded to numeric to use the two-argument form of round. You can see that PostgreSQL is expanding it in the output). (In the above, note that float8 is just a shorthand alias for double precision. Regress=> SELECT round( CAST(float8 '3.1415927' as numeric), 2)

Pg_catalog | round | numeric | numeric, integer | normal Pg_catalog | round | numeric | numeric | normal Pg_catalog | round | double precision | double precision | normal Pg_catalog | dround | double precision | double precision | normal Schema | Name | Result data type | Argument data types | Type regress=> SELECT round( float8 '3.1415927', 2 ) ĮRROR: function round(double precision, integer) does not exist For reasons Sherrill 'Cat Recall' explains in the comments, the version of round that takes a precision is only available for numeric. PostgreSQL does not define round(double precision, integer).
Postgres round to 2 decimals how to#

In postgresql how can I select rows where a jsonb array contains objects?.Creating functions and triggers in PostgreSQL with SQLAlchemy.Unable to build Hibernate SessionFactory - spring data/ jpa/ hibernate reverse engineering.
Postgres round to 2 decimals driver#
