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.
Step 1: Go to Server > Data Export. Alternatively you can right click on a table in the Schema Browser on the left and select Data Export. However, this only exports a single table (even if you select multiple tables). To use the MySQL Workbench export database feature, you have to use the Server > Data Export option.
The SQL INSERT INTO SELECT Statement The INSERT INTO SELECT statement copies data from one table and inserts it into another table. The INSERT INTO SELECT statement requires that the data types in source and target tables match. Note: The existing records in the target table are unaffected.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With