问题描述
当我需要在Order表中检索一些信息时,jasper无法从PGmoney转换为double。我先搜索谷歌,但没有结果。
When I need to retrieve some information in Order table, jasper cannot cast from PGmoney to double. I searched google first, but no have result of this.
你知道如何修复它吗?
注意:我使用PostgreSQL数据库。
Note: I use PostgreSQL database.
推荐答案
这是PostgreSQL 钱$的几个原因之一c $ c>类型。奇怪地不同意这一点,并认为应该使用它不鼓励。
This is one of the several reasons the PostgreSQL money
type was deprecated and should be avoided. Oddly newer versions of the same documentation don't show the deprecation warning but I and others disagree with that and think its use should be discouraged.
如果可能的话,将模式更改为使用 numeric
,而不是像 numeric(17,2)
如果您只想存储整数美分,或者更精确地存储中间值。在HQL中使用 money
进行一场噩梦,即使是Java的 BigDecimal
类也是如此(通常用于映射数字
字段)尽管它的算法语法非常笨拙但是更好。
If at all possible, change your schema to use numeric
instead, like numeric(17,2)
if you only want to store whole-number cents, or something more precise for intermediate values. You'll have a nightmare of a time working with money
in HQL, to the point where even Java's BigDecimal
class (usually used to map numeric
fields) is better despite the awfully clumsy syntax of itsw arithmetic.
我会做一个 ALTER TABLE blah ALTER COLUMN blahcol TYPE numeric(17,2)USING(regexp_replace(blahcol :: text,'[$,]','','g'):: numeric);
并且如果我是你的话,忘记 money
类型。
I'd do an ALTER TABLE blah ALTER COLUMN blahcol TYPE numeric(17,2) USING ( regexp_replace(blahcol::text, '[$,]', '', 'g')::numeric );
and forget the money
type existed if I were you.
这篇关于Jasper报告:无法获得类'org.postgresql.util.PGmoney'的字段'x'的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!