如何使用 mysqlimport 累积结果

发布于 2024-08-19 04:58:48 字数 372 浏览 4 评论 0原文

我喜欢 mysqlimport,它速度快且相对易于使用(比用于导入 > 20GB 数据文件的 PHP 或 Python 前端要快得多)。不过我想做以下事情。我有一个数据文件,如下所示:

cat dog 7
Cat Dog 3
CaT DOG 1

字段为 varchar, varchar, int

我希望最终结果存储为 ['cat', 'dog', 11],即,如果结果不存在,我希望将其插入到数据库中,如果存在,则将其添加(如数学意义上的)到现有数据库中,同时忽略前两个字段的情况。我在 python 中有一个工作解决方案,但我正在寻找 mysql(import) 中的本机解决方案。

I like mysqlimport, its fast and relatively easy to use (much faster then say, PHP or Python front-ends for importing > 20GB data files). However I'd like to do the following. I have a data file that looks like:

cat dog 7
Cat Dog 3
CaT DOG 1

with the fields as varchar, varchar, int

And I would like the final result to be stored as ['cat', 'dog', 11], i.e. I'd like the result to be inserted into the database if it doesn't exist and added (as in mathematical sense) to the existing one if it does while ignoring the case of the first two fields. I have a working solution in python, but I am looking for a native in mysql(import).

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

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

发布评论

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

评论(1

云归处 2024-08-26 04:58:48

为了区分大小写,您可能可以将所有内容降级为小写(有一个函数可以实现这一点)。如果要将其连接到上一个条目,请检查 MySQL 字符串函数

如果只想插入不存在的记录,请选中 REPLACE 插入重复

For case sensitivity you could probably downgrade everything into lowercase (there's a function for that). If you want to concatenate it to previous entry, check MySQL string functions.

If you want to insert a record only if it does not exist, check REPLACE or INSERT ON DUPLICATE.

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