25

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.

2 Answers 2

41

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

Sign up to request clarification or add additional context in comments.

2 Comments

What does the (10,2) represent? Does it mean it'll accept a value up to 9999999999.99?
I see now that the first number is the entire length of the number (excluding the point) so the maxval for (10,2) would be 99999999.99
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.