开发者

mysql insert nested select from other db truncates double values

I have a table in one database, call this db x. I have another database, call it y. I want to copy data from x.some_table to y.some_table. I don't want to do an exact copy of the table, because some columns don't make sense in database b. I use the following query:

INSERT INTO y.some_table (a_field) SELECT a_field FROM x.some_table;

a_filed in both tables is defined as DOULBE(17,0). If i run this: USE y; SELECT a_field FROM x;

Then I get output with full values --no floating-point truncation. However, if after insertion using the first query I showed, I get nothing but whole numbers in y's some_table.a_field. The floating-point remainders are truncated.

What am I doing wro开发者_开发技巧ng? Thanks.


Are you sure that the column is defined as DOUBLE(17,0) in both tables? Doesn't that specify 17 total digits with 0 after the decimal? If so you're select from table x should also have 0 decimal places. If its defined differently in x say DOUBLE(17,6) and you are trying to insert it into DOUBLE(17,0) then the decimals will be truncated I believe.


Not sure what is causing truncation .. you can make sure that you properly set the floating type .. if you think your table definition is OK, you can create a script to test it for example, in PHP you could do something like -

$sql = "SELECT your_select_field FROM your_table";
$result = mysql_query($sql);

while($row = mysql_fetch_assoc($result)) {
   $sql_ins = "INSERT INTO your_insert_table SET your_field = '".$row['your_select_field']."' ";
   $res_ins = mysql_query($sql_ins);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜