嗨,我是 postgres 的新手, 在将数据插入货币类型字段时,我收到错误消息 as.. 这里我的示例表是
CREATE TABLE x_table
(
t_name character varying(40) NOT NULL,
currency money
)
INSERT INTO x_table(t_name, currency)
VALUES ('TEST', 1000);
并得到错误信息
错误:“currency”列是货币类型,但表达式是整数类型
SQL 状态:42804
。
所以谁能说说如何解决这个.. 提前致谢
最佳答案
在现代版本(使用 9.1 和 9.3 测试)中,上面的代码示例按原样工作。
在旧版本中,没有从 integer
到 money
的隐式转换定义。
Quoting the the release notes for Postgres 9.1:
Add support for casting from
int4
andint8
tomoney
(Joey Adams)
此外,请务必考虑存储货币信息的替代方案:
PostgreSQL: Which Datatype should be used for Currency?
关于sql - 如何在 postgres 中插入货币数据类型值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24001341/