Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy blob data from one table to another on MySQL

Tags:

sql

copy

mysql

blob

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.

like image 548
Lailson Bandeira Avatar asked Aug 17 '09 00:08

Lailson Bandeira


People also ask

How do I export BLOB data from MySQL workbench?

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.

How do I transfer data from one table to another?

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.


1 Answers

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.

like image 118
Lailson Bandeira Avatar answered Sep 23 '22 04:09

Lailson Bandeira