SQL PostgreSQL - 更改数字的精度?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21726409/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PostgreSQL - change precision of numeric?
提问by Andrius
I tried to change precision like this:
我试图像这样改变精度:
ALTER Table account_invoice ALTER amount_total SET NUMERIC(5);
But I get syntax error, so I'm clearly doing something wrong. What is the right syntax to change precision of numeric in PostgreSQL?
但是我遇到了语法错误,所以我显然做错了什么。在 PostgreSQL 中更改数字精度的正确语法是什么?
回答by huzeyfe
Try this:
尝试这个:
ALTER Table account_invoice ALTER COLUMN amount_total TYPE DECIMAL(10,5);
DECIMAL(X, Y)
-> X represents full length and Y represents precision of the number.
DECIMAL(X, Y)
-> X 代表全长,Y 代表数字的精度。
回答by Maike Mota
You can use this:
你可以使用这个:
ALTER Table account_invoice ALTER amount_total SET DATA TYPE NUMERIC(5,Y);
where Y is your required level of precision.
其中 Y 是您所需的精度级别。
回答by GarethD
You need to ue the TYPE
keyword after the column name, not SET
您需要TYPE
在列名后使用关键字,而不是 SET
ALTER Table account_invoice ALTER amount_total TYPE NUMERIC(5);
See the docs: ALTER TABLE
查看文档:ALTER TABLE