Reputation: 239810
Thanks to a last minute client request a integer field in our database now needs to be a decimal, to two points.A value of 23
should become 23.00
.
Is there a nice way I can convert the table and cast the data across?
I'll freely admit, I haven't done anything like this with PostgreSQL before so please be gentle with me.
Upvotes: 25
Views: 26118
Reputation: 1
alter table table_name alter column columname type decimal(16,2);
for converting data type from int to decimal. with precession after decimal point 2 values it will come for example 10.285 then it will be 10.23.or in decimal place we can use numeric also it will work.
Upvotes: 0
Reputation: 28574
Something like this should work:
alter table t alter column c type decimal(10,2);
Edit:
As @Oli stated in the comments; the first number is the entire length of the number (excluding the point) so the maxval for (10,2)
would be 99999999.99
Upvotes: 41