0

I know there are lots of bugs like this around here but this query seems to be different, as it's an insert query. Here is the schema for the table card_info:

CREATE TABLE card_info (
 card_id mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
 card_name_orig varchar(150) NOT NULL,
 card_name_html varchar(150) NOT NULL,
 card_name_search varchar(150) NOT NULL,
 card_name_page varchar(150) NOT NULL,
 card_cost varchar(50) DEFAULT NULL,
 card_cost_converted tinyint(2) NOT NULL DEFAULT '0',
 card_subtype varchar(75) DEFAULT NULL,
 card_oracle_text_orig text,
 card_oracle_text_html text,
 card_power varchar(10) DEFAULT NULL,
 card_toughness varchar(10) DEFAULT NULL,
 card_loyalty tinyint(1) DEFAULT NULL,
 PRIMARY KEY (card_id),
 KEY card_name_nd (card_name_search),
 KEY card_name_page (card_name_page),
 KEY card_cost_converted (card_cost_converted),
 KEY card_power (card_power),
 KEY card_toughness (card_toughness),
 KEY card_loyalty (card_loyalty),
 FULLTEXT KEY card_oracle_text_orig (card_oracle_text_orig),
 FULLTEXT KEY card_name_search (card_name_search)
) ENGINE=MyISAM DEFAULT CHARSET=utf8

And here is my query:

INSERT INTO card_info (
 card_name_orig, card_name_html, card_name_search, card_name_page, card_cost,
 card_cost_converted, card_subtype, card_oracle_text_orig, card_oracle_text_html,
 card_power, card_toughness, card_loyalty
)
SELECT DISTINCT
 d.name_orig, d.name_html, d.name_search, d.name_page, d.cost,
 COALESCE(d.cost_converted, 0),   d.type_sub, d.oracle_text_orig,
 d.oracle_text_html, d.`power`, d.toughness, d.loyalty
FROM card_info_de d
LEFT OUTER JOIN card_info i ON d.name_search = i.card_name_search
WHERE i.card_id IS NULL
AND d.edition_id = 'isd'
ORDER BY (d.collector_number + 0), d.collector_number;

If I perform this query, I'm getting this error:

1292 - Truncated incorrect DOUBLE value: '181a'

Please note that the value 181a is from the column card_info_de.collector_number and it is a VARCHAR(5) field, and that field isn't being inserted to the card_info table anyway, it's just being used in the order clause of the select query.

If I do the query starting from the SELECT only, I can see the correct results are being selected, but when I do the insert, it gives me the error above. Do note that If I remove the ORDER BY clause from the SELECT query, it inserts fine. I don't have a clue what I'm doing wrong.

Thanks in advance.

4

2 回答 2

5

我自己也遇到了同样的错误,这有点误导。我在另一个线程中找到了答案:

错误代码 1292 - 截断不正确的 DOUBLE 值 - Mysql

此消息表示您正在尝试比较WHEREorON子句中的数字和字符串。要么确保它们具有相似的声明,要么使用显式CAST将数字转换为字符串。

如果关闭strict模式,错误应该会变成警告。

巴尔马尔

所以基本上检查这些列是否被视为错误的数据类型:

d.name_search i.card_name_search d.edition_id d.collector_number

于 2018-02-14T11:15:29.837 回答
0

尝试

ORDER BY (d.collector_number + '0'), d.collector_number;

如果是真的很糟糕,但很有可能。

于 2011-11-19T14:12:21.423 回答