views:

317

answers:

2

Hi, I have a table with 3 columns, 2 of which are auto-incrementing. I have a text file with various content that I would like to insert into the 3rd column. In that text, values are separated as such:

"value1", "value2", "value3", "etc",

How would I go about inserting all those values into a specific column, while being able to use the above format for my initial content(or something similar that I could do by a "replace all"), hopefully with a single command in phpmyadmin?

Let me know if my question is not clear!

Thanks in advance

A: 

First, I would if at all possible get that text file in the right format which woulde be 1 column with each value on a separate line. Other wise, you need to first write a funtion to split the data into sometype of one column temp table and then insert by joining to the table. If the text file is in a reasonable format instead of a comma delimited mess, then you can directly insert it in a bulk operation in most databases.

HLGEM
Well I only know one column`s values. The other ones are auto-increment, and I would rather not have to force that numerical value by organizing things such as : "row1", "value1", "auto1" etc. Is there no way to automate the process without any further steps, with what I have right now?
skarama
A: 

Use a regular expression to convert each value into a full Insert query on a separate row:

INSERT INTO mytable (column3) VALUES ('value1')

Something like this should do it:

Match: "\([^"]*\)", 
Replace with: INSERT INTO mytable (column3) VALUES ('\1') \n
vincebowdren