简体   繁体   中英

Way to omit MySQL column count on insert

I am trying to insert a large dump of custom CMS's news section into WordPress. Unfortunalety, columns doesn't match. Some of them - yeah, sure - like title, date or content. But WordPress required a lot of columns which this dump doesn't have. Is there a way to either omit this count on insert or filling it with dummy (preferably blank) data? Search and replace (even with regular expressions) won't do here, since it is really huge file and simple 'find' takes a lot of time.

You stated that you were given a "table." If it included a schema, create the table and insert the data. Otherwise, create the table based on the data columns and insert your data. This is considered your staging table. You can now write a SELECT statement to select the data from your staging table that will be inserted into your destination table. You will finally prepend an INSERT statement to insert your selected data. It should look something like this:

INSERT INTO destinationTable (fruits, animals, numbers, plants)
SELECT fruits, animals, numbers, '' FROM stagingTable

If you did not have plants in your staging table, you would simply SELECT '' or SELECT NULL for that column. You can then simply drop your staging table.

Assuming the answer to my clarification is yes, you can insert multiple rows by delimiting them with a column.

INSERT INTO table (col1, col2) 
VALUES (row1val1, row1val2),
(row2val1,row2val2)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM