padding - PostgreSQL adds trailing zeros to numeric -


recently migrated db postgresql has columns defined numeric(9,3) , numeric(9,4). in testing app have found when data saved these columns there trailing zeros being added value inserted. using hibernate, , logs show correct values being built prepared statements.

an example of data inserting 0.75 in numeric(9,3) column , value stored 0.750. example numeric(9,4) column: insert value 12 , db holding 12.0000.

i found related question: postgresql numeric type without trailing zeros. did not offer solution other quote 9.x documentation saying trailing zeros not added. question, answer quoted docs (which have read) said:

numeric values physically stored without leading or trailing zeroes. thus, declared precision , scale of column maximums, not fixed allocations.

however, question poster, see trailing zeros being added. raw insert generated hibernate in logs not show baggage. assuming postgresql thing have not set correctly, can't find how got wrong.

if specify precision , scale, pg pads precision , scale.

regress=> select '0'::numeric(8,4);  numeric  ---------   0.0000 (1 row) 

there's no way turn off. it's still same number, , precision defined type, not value.

if want have precision defined value have use unconstrained numeric:

regress=> select '0'::numeric, '0.0'::numeric;  numeric | numeric  ---------+---------        0 |     0.0                                                                                                                                                              (1 row)                                                                                                                                                                         

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -