在 LOAD DATA INFILE 期间触发跳过某些插入

发布于 2024-09-03 02:29:47 字数 450 浏览 2 评论 0原文

首先,一个简化版本:我想知道是否可以创建一个触发器在 INSERT 期间激活(它实际上是 LOAD DATA INFILE)并且不输入表中已有的 RMA 记录?

我有一个没有唯一记录的表。有些可能是合法的重复项,但我可以使用一个字段来了解数据是否已输入。例如

RMA     Op     Days
---------------------
213   Repair   0.10
213    Test    0.20
213   Repair   0.10

,我可以对三列一起创建索引,但正如您所看到的,RMA 可能会在一个步骤中出现两次相同的时间,因此可能会有重复的记录。基本上,我希望触发器说如果 NEW.rma 已在表中,则跳到下一行。

我发现有一些方法可以使触发器停止插入,所以我想我现在的问题是,如何在 LOAD DATA INFILE 调用期间跳过插入并继续其余部分?

First of, a simplified version: I am wondering if I can create a trigger to activate during INSERT (it's actually LOAD DATA INFILE) and NOT enter records for an RMA already in my table?

I have a table that has no records that are unique. Some may be legitimate duplicates but there is one field that I can use to know if the data has been entered or not. For instance

RMA     Op     Days
---------------------
213   Repair   0.10
213    Test    0.20
213   Repair   0.10

So I could do an index on the three columns together but as you see it's possible for an RMA to be in a step for the same amount of time twice so it's possible to have duplicate records. Basically, I want the Trigger to say if NEW.rma is in the table already, skip to the next row.

I found out there are ways to make a Trigger halt the Insert so I guess my question now is, how can I skip an insert and continue with the rest during a LOAD DATA INFILE call?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

一曲爱恨情仇 2024-09-10 02:29:47

不需要使用锁表...这样做(我说表名称是 rmainfo ):

create table rmainfo_new like rmainfo;
load data infile 'filename' into table rmainfo_new;
rename table rmainfo to rmainfo_old,rmainfo_new to rmainfo;
drop table rmainfo_old;

您也可以将删除表放在开头(使其DROP TABLE IF EXISTS rmainfo_old),这将在运行之间保留 _old 表以供备份/参考

no need to use lock tables...do it this way (I am saying table name is rmainfo):

create table rmainfo_new like rmainfo;
load data infile 'filename' into table rmainfo_new;
rename table rmainfo to rmainfo_old,rmainfo_new to rmainfo;
drop table rmainfo_old;

you can also put the drop table at the beginning (make it DROP TABLE IF EXISTS rmainfo_old), which will leave the _old table between runs for backup/reference

乜一 2024-09-10 02:29:47

您能否设置从 RMA 和 OP 派生的复合密钥?这会导致重复的条目显示为错误。

Could you set up a compound key derived from the RMA and the OP? That would cause duplicate entries to show up as errors.

野生奥特曼 2024-09-10 02:29:47

我能想到的最简单的方法是加载到新表中,然后删除旧表并重命名新表。 LOCK TABLES 应该能够在最后隔离该开关。

或者,如果您确定插入文件中行出现的顺序 - 即,如果保证文件中旧行后跟新行 - 那么您可以COUNT(*) 首先,然后在加载时跳过该行数。

The simplest way I can think of is to load into a new table, then delete the old and rename the new. LOCK TABLES should be able to isolate that switch at the end.

Alternatively, if you are sure about the order in which rows appear in the insert file - i.e., if it is guaranteed that the file has the old rows followed by the new rows - then you can COUNT(*) first, then skip that number of rows when loading.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文