Using PostgreSQL 9.2 on Windows Server 2007, I have the following table:
CREATE TABLE aaa_dens (read_no INT, position REAL PRIMARY KEY);
Some values in position
have 4 or more digits after the decimal point, as shown from a dump:
$ head dump.txt
"read_no" "position"
"1" "150.83"
"2" "150.8308"
"3" "150.8316"
"4" "150.8324"
"5" "150.83321"
"6" "150.834"
"7" "150.83479"
"8" "150.8356"
"9" "150.8364"
However, SELECT * FROM aaa_dens;
shows only a max of 3 digits after the decimal point:
read_no | position
---------+----------
1 | 150.83
2 | 150.831
3 | 150.832
4 | 150.832
5 | 150.833
6 | 150.834
7 | 150.835
8 | 150.836
9 | 150.836
Furthermore, trying to convert position
to numeric(8,4)
yields an error, as if it had rounded reads 3 and 4 to 150.832:
ALTER TABLE aaa_dens ALTER COLUMN position TYPE NUMERIC(8,4);
ERROR: could not create unique index "pk_aaa_dens"
DÉTAIL : Key ("position")=(150.8320) is duplicated.
What exactly is happening here and how to fix it?
numeric
from start, notreal
. Do you get the same error if you try to change it intonumeric(10,6)
?numeric
.