佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 2012|回复: 4

mysql postgresql 同样资料,select query的结果不同

[复制链接]
发表于 9-12-2012 10:24 AM | 显示全部楼层 |阅读模式
最近测试自己写的分析软件。以下是我做的column:
mysql: column name "price1", datatype decimal 12,8 column name "volumn", datatype decimal 12,8  postgresql:column name  "price1" datatype numeric, column name "volumn" datatype numeric. 在执行大多数的query时两个db的答案都一样,只有在乘3,4的时候会出现偏差,而且精确度跌到一个小数点。这是为什么呢?谢谢。
回复

使用道具 举报


ADVERTISEMENT

发表于 12-12-2012 09:54 PM | 显示全部楼层
一个是datatype decimal 12,8,一个是datatype numeric,有试过把第2个改成precision 12 ,  scale 8吗?
回复

使用道具 举报

 楼主| 发表于 8-1-2013 03:02 PM | 显示全部楼层
yan13 发表于 12-12-2012 09:54 PM
一个是datatype decimal 12,8,一个是datatype numeric,有试过把第2个改成precision 12 ,  sc ...

postgresql 不能改,只能用numeric. mysql改去  `price` decimal(50,23) DEFAULT NULL,结果还是一样。

回复

使用道具 举报

发表于 3-2-2013 08:55 PM | 显示全部楼层
ltk1984 发表于 8-1-2013 03:02 PM
postgresql 不能改,只能用numeric. mysql改去  `price` decimal(50,23) DEFAULT NULL,结果还是一样。

...

根據 Official documents 應該是可以改
全文在這裡:http://www.postgresql.org/docs/9.1/static/datatype-numeric.html

8.1.2. Arbitrary Precision Numbers 第二個paragraph:

We use the following terms below: The scale of a numeric is the count of decimal digits in the fractional part, to the right of the decimal point. The precision of a numeric is the total count of significant digits in the whole number, that is, the number of digits to both sides of the decimal point. So the number 23.5141 has a precision of 6 and a scale of 4. Integers can be considered to have a scale of zero.
Both the maximum precision and the maximum scale of a numeric column can be configured. To declare a column of type numeric use the syntax:
NUMERIC(precision, scale)
回复

使用道具 举报

发表于 6-2-2013 11:47 AM | 显示全部楼层
iammyself 发表于 3-2-2013 08:55 PM
根據 Official documents 應該是可以改
全文在這裡:http://www.postgresql.org/docs/9.1/static/dataty ...

postgresql 不能改,只能用numeric.  
我当时第一个印象是postgresql 有data,不能改,不然就是顾客不让改。
只有在乘3,4的时候会出现偏差,而且精确度跌到一个小数点
印象中很久前有遇过这个问题。好像是2个fields 不一样,或不同的rounding。但没亲眼看到,不敢乱讲。
大家新年快乐
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 23-11-2025 07:14 AM , Processed in 0.181801 second(s), 28 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表