Sample Header Ad - 728x90

How to prevent PostgreSQL from automatically rounding numeric types?

2 votes
3 answers
12213 views
I have a simple schema and query for a MWE. Schema: CREATE TABLE ttable ( tcol Numeric(19,4) ) Query: INSERT INTO ttable (tcol) VALUES ('123.45678'); SELECT * FROM ttable; Fiddle Result: 123.4568 In this case, I have lost precision. I entered five decimal places, but Postgres automatically rounded down to four. I want this to be an error, or at least a warning of some kind that I can detect, so that I can tell the user about the loss of precision. How can I make this happen? Edit: This question is obviously not a duplicate of this question . In that question, the user is using a client application which is rounding value below the stored precision. My question is about Postgres itself rounding the data to fit, not the client displaying. This would be obvious to anyone who looked further than the title of both questions.
Asked by TechnoSam (139 rep)
Dec 21, 2020, 03:25 PM
Last activity: Dec 22, 2020, 07:41 PM