Search code examples
mysqlsqladaption

Equivalent of SET with LOAD DATA INFILE for MySQL 4.1?


I'd to use LOAD DATA INFILE to load a .txt file.

The file contains data for only some of the columns, so I'd like to use SET to specify the value of one of the columns not included in the file.

Here's the syntax I'd use:

LOAD DATA LOCAL INFILE 'file.txt'
INTO TABLE some_table
FIELDS TERMINATED BY ','
(column1, column2, column3)
SET column4 = 100

The problem is that SET is only an option in MySQL 5.0; unfortunately, I'm stuck using MySQL 4.1.

Is there an equivalent way to accomplish this using v. 4.1?


Solution

  • Too long for a comment, so posting as answer.

    I never had to work with versions prior 5.0, so just asking have you tried

    LOAD DATA LOCAL INFILE 'file.txt'
    INTO TABLE some_table
    FIELDS TERMINATED BY ','
    (column1, column2, column3, 400)
    

    or omit column4

    LOAD DATA LOCAL INFILE 'file.txt'
    INTO TABLE some_table
    FIELDS TERMINATED BY ','
    (column1, column2, column3)
    

    and then

    UPDATE some_table SET column4 = 400;
    

    ? Column4 must have a default value for this. In case it doesn't have, you can easily add one with an ALTER TABLE statement.