将 blob 数据从 MySQL 上的一个表复制到另一个表
我需要将一组数据从一个表复制到另一个包含 BLOB 列的表。我使用带有子查询 SELECT
的 INSERT
查询:
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技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里玩了一下,发现错误:原来的列是
MEDIUMBLOB
,而不是BLOB
。当我纠正类型时它工作得很好。抱歉问了这个愚蠢的问题。After playing a bit here, I found the error: the original column is a
MEDIUMBLOB
, not aBLOB
. It works fine when I just correct the type. Sorry for the dumb question.