1

I have a pre-defined table (with data) in a MySQL database with 3 columns:

brandId INT AUTO_INCREMENT,
brand CHAR,
insertDateTime DATETIME

And I have a list of brands stored in a csv file (10,000 rows).

I want to insert the brands into the table as new rows, with insertDateTime shows the date time of the insertion.

I know I can use LOAD DATA INFILE to load the brands from the csv, and I can use the NOW() function to compute insert datetime as we go, but how to combine them in one query?

1 Answer 1

1

You can use the SET clause of LOAD DATA to provide values that do not come from the input file.

Consider the following syntax:

LOAD DATA INFILE 'myfile.csv'
INTO TABLE mytable (brand)
SET insertDateTime = NOW();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.