O
O
old_stalin2020-10-11 21:16:11
Python
old_stalin, 2020-10-11 21:16:11

How to solve problem with round in python (PostgreSQL)?

The round function does not work up to a specific decimal point.

cursor.execute(f"SELECT round(cash,0) FROM users WHERE id = 694973241827000421")

An error is thrown:
cursor.execute(f"SELECT round(cash,0) FROM users WHERE id = 694973241827000421")
psycopg2.errors.UndefinedFunction: function round(double precision, integer) does not exist
LINE 1: SELECT round(cash,0) FROM users WHERE id = 69497324182700042...
               ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alan Gibizov, 2020-10-11
@old_stalin

Perhaps because round with precision only accepts the numeric type, while your cash has the double precision type.
Cast cash to numeric and try rounding.
Or do not specify the rounding precision, then you can leave dp.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question