gpt4 book ai didi

mysql - 尝试将一个表插入另一个表时出现问题

转载 作者:行者123 更新时间:2023-11-30 23:21:21 25 4
gpt4 key购买 nike

我在临时表中有一个包含 150 万条记录的 mysql 表,我想通过内部连接将其插入到主表中。

我的代码可以运行,但在 103,613 条记录处停止。 IT 不会继续前进。为什么会停下来?为什么它没有一直走到尽头?

这是我当前的代码

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 查询?

最佳答案

“没有默认值”问题是源表在新表上定义为 S NOT NULL 的列有空值,而这些列没有用默认值定义。 p>

您有三种选择来解决此问题:

  1. 将目标列定义为可为空(省略 NOT NULL)
  2. 使用默认值定义目标列,即 NOT NULL DEFAULT 'some value'
  3. 如果列为空,则提供一个值,即 SELECT ifnull(source_column, 'some value)

Truncated incorrect INTEGER value 问题,您从 char 值中选择并将其放入 int 列中,但有些 vyes 是空白的,因此您需要处理该问题:

select if(source_column = '', 0, source_column)

存在列数据被截断 的问题,因为源值大于/长于目标列可以容纳的值。要修复,请将目标列定义为更大(bigint 而不是 int)或更长(例如 text 或 varchar(80) 而不是 varchar(20))

关于mysql - 尝试将一个表插入另一个表时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15305333/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com