我有一个临时表中有150万条记录的mysql表,我想用一个内部连接将它插入到主表中。
我的代码可以工作,但它停在103,613条记录。它不会一直走下去。为什么它会停止呢?为什么它不能一直走到最后呢?
这是我当前的代码
INSERT INTO phone_calls(next_attempt, created_on, modified_on, status, call_subject,
account_number, call_code, last_attempt_on, total_attempts, account_id
,team_id
,campaign_id
,call_code_id
,result_code
,result_code_id
,time_zone_id
,trigger_on
,first_attempt_on
,first_attempt_by
,last_attempt_by
,modified_by
,client_id
,last_call_id
,call_notes
,owner_id
,industry_id
)
SELECT
CASE WHEN next_attempt IS NULL OR next_attempt = '' THEN STR_TO_DATE(replace(t.next_attempt,'/',','),'%m,%d,%Y %T') END as next_attempt,
CASE WHEN t.created_on IS NULL OR t.created_on = '' THEN '0000-00-00 00:00:00' ELSE STR_TO_DATE(replace(t.created_on,'/',','),'%m,%d,%Y %T') END as created_on,
CASE WHEN t.modified_on IS NULL OR t.modified_on = '' THEN '0000-00-00 00:00:00' ELSE STR_TO_DATE(replace(t.modified_on,'/',','),'%m,%d,%Y %T') END AS modified_on,
CONVERT( CASE WHEN t.status IS NULL OR t.status = '' THEN 0 ELSE t.status END, UNSIGNED INTEGER) AS status,
LEFT(IFNULL(t.call_subject, ''), 100),
t.account_number,
CONVERT( CASE WHEN t.callcode IS NULL OR t.callcode = '' THEN 0 ELSE t.callcode END , UNSIGNED INTEGER) AS callcode, STR_TO_DATE(replace(t.last_attempt_on,'/',','),'%m,%d,%Y %T') as last_attempt_on,
CONVERT( CASE WHEN t.New_Attempts IS NULL OR t.New_Attempts = '' THEN 0 ELSE t.New_Attempts END , UNSIGNED INTEGER) AS New_Attempts,
a.account_id
,0
,0
,0
,0
,0
,0
, '0000-00-00 00:00:00'
, '0000-00-00 00:00:00'
,1
,1
,1
,1
,0
,'IMPORTED FROM CRM'
,1
,1
FROM tmp_table_for_rdi_cms AS t
INNER JOIN accounts AS a ON a.account_number = t.account_number LIMIT 9999999999;
these 2 fields are indexed so it runs fast
a.account_number
t.account_number现在,我知道我没有为某些类型为无符号整数的字段插入任何值,但这没有关系,因为我将在稍后更新此内容。
如何在不丢失任何记录的情况下执行此INSERT INTO查询?
发布于 2013-03-09 08:02:51
“没有缺省值”的问题是,源表对新表上定义为S NOT NULL的列具有空值,并且这些列没有定义默认值。
您有三个选择来解决这个问题:
截断了不正确的整数值问题,您正在从char值中进行选择并将其放入int列中,但有些vyes是空的,因此您需要处理此问题:
select if(source_column = '', 0, source_column)
由于列问题而截断的数据存在,因为源值比目标列可以容纳的值大/长。要修复,请将目标列定义为更大(bigint而不是int)或更长(例如text或varchar(80)而不是varchar(20))
https://stackoverflow.com/questions/15305333
复制相似问题