如何将数据类型十进制分配给 Postgresql 中的列?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15286040/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 00:49:40  来源:igfitidea点击:

How can I assign a data type decimal to a column in Postgresql?

postgresqlpostgresql-9.1

提问by Chris Travers

I'm working with postgresql-9.1 recently.

我最近在使用 postgresql-9.1。

For some reason I have to use a tech which does not support data type numeric but decimal. Unfortunately, the data type of columns which I've assigned decimal to them in my Postgresql are always numeric. I tried to alter the type, but it did not work though I've got the messages just like "Query returned successfully with no result in 12 ms".

出于某种原因,我必须使用一种不支持数字但十进制数据类型的技术。不幸的是,我在 Postgresql 中为它们分配了十进制的列的数据类型始终是数字。我尝试更改类型,但它不起作用,尽管我收到了类似“查询成功返回,12 毫秒内没有结果”之类的消息。

SO, I want to know how can I get the columns to be decimal.

所以,我想知道如何将列设为十进制。

Any help will be highly appreciate.

任何帮助将不胜感激。

e.g.

例如

My creating clauses:

我的创造条款:

CREATE TABLE IF NOT EXISTS htest
(
  dsizemin decimal(8,3) NOT NULL,
  dsizemax decimal(8,3) NOT NULL,
  hidentifier character varying(10) NOT NULL,
  tgrade character varying(10) NOT NULL,
  fdvalue decimal(8,3),
  CONSTRAINT htest_pkey PRIMARY KEY (dsizemin , dsizemax , hidentifier , tgrade )
);

My altering clauses:

我的修改条款:

ALTER TABLE htest
ALTER COLUMN dsizemin TYPE decimal(8,3);

But it does not work.

但它不起作用。

回答by Chris Travers

In PostgreSQL, "decimal" is an alias for "numeric" which poses some problems when your app thinks it expects a type called "decimal" from the database. As Craig noted above, you can't even create a domain called "decimal"

在 PostgreSQL 中,“decimal”是“numeric”的别名,当您的应用程序认为它需要来自数据库的称为“decimal”的类型时,这会带来一些问题。正如 Craig 上面提到的,你甚至不能创建一个名为“decimal”的域

There is no good workaround in the database side. The only thing you can do is change the application to expect a numeric data type back.

数据库端没有很好的解决方法。您唯一能做的就是更改应用程序以期望返回数字数据类型。