Re: MySQL: Load Data Infile

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>> LOAD DATA INFILE 'persondata.txt' INTO TABLE persondata (col1,col2,...);

Syntax isn't quite correct with field and line terminators specified.

>>
>> You must also specify a column list if the order of the fields in the
input
>> file differs from the order of the columns in the table. Otherwise,
MySQL
>> cannot tell how to match input fields with table columns.
>> </mysql manual>
>>
>> <http://dev.mysql.com/doc/refman/4.1/en/load-data.html>
>>
>> Best Regards,
>>
>> Oliver

> Ah, thanks for the nudge, Oliver!
>
> I had the manual open but I'm used to the 4.0.** series, and now I
realize this is on an older 3.23.58 version.
> I had forgotten about this legacy system.

For the archives, or any currently interested listers.

The MySQL manual for the 3, 4.0, and 4.1 series does not have an example
for specifying a column list with field and line terminators that I could
find, but this syntax works:

$query = "load data infile 'data.tx' into table tablename fields terminated
by ',' lines terminated by '\r\n' (fld2, fld1, fld3)";

It's counterintuitive I think to have the field list after the terminator
specifications instead of following the tablename, but that's the only way
I got it to work.

David

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux