开发者

Alter PostgreSQL column from integer to decimal

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?

开发者_Go百科

I'll freely admit, I haven't done anything like this with PostgreSQL before so please be gentle with me.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜