将 blob 数据从 MySQL 上的一个表复制到另一个表

发布于 2024-08-02 10:51:00 字数 407 浏览 6 评论 0原文

我需要将一组数据从一个表复制到另一个包含 BLOB 列的表。我使用带有子查询 SELECTINSERT 查询:

INSERT INTO dest_table(field1, field2, field3, blobfield, field4) 
    (SELECT t.myfield1, t.myfield2, t.id, t.blobfield, 'SomeConstant' 
        FROM tablename t)

BLOB 之外,所有字段都被正确复制。我知道我错过了一些东西,但我不知道如何使其发挥作用。搜索对我没有帮助。有人知道如何解决吗?

我更喜欢纯 SQL 的解决方案,但我也可以使用 Ruby。

I need to copy a set of data from one table to another that includes a BLOB column. I'm using an INSERT query with a subquery SELECT:

INSERT INTO dest_table(field1, field2, field3, blobfield, field4) 
    (SELECT t.myfield1, t.myfield2, t.id, t.blobfield, 'SomeConstant' 
        FROM tablename t)

All fields get copied correct, except the BLOB. I know I'm missing something, but I have no idea on how to make this work. Search did not help me. Anyone know how to solve it?

I'd prefer a solution in pure SQL, but I can use Ruby too.

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

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

发布评论

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

评论(1

梦冥 2024-08-09 10:51:00

这里玩了一下,发现错误:原来的列是MEDIUMBLOB,而不是BLOB。当我纠正类型时它工作得很好。抱歉问了这个愚蠢的问题。

After playing a bit here, I found the error: the original column is a MEDIUMBLOB, not a BLOB. It works fine when I just correct the type. Sorry for the dumb question.

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