Lailson Bandeira
Lailson Bandeira

Reputation: 764

Copy blob data from one table to another on MySQL

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.

Upvotes: 6

Views: 7920

Answers (1)

Lailson Bandeira
Lailson Bandeira

Reputation: 764

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.

Upvotes: 8

Related Questions