2uzhan.com
Advertisement
Now Place:2uzhan.com » Can not use "fields terminated by" while loading data into specific columns?

Can not use "fields terminated by" while loading data into specific columns?

MySQL @ February 1, 2007   Views:0

Hello, I have a question, can I specify which columns to insert data when I load data from local file, while as the same time I can use fields seperated by?

Seems that I can not use "fields seperated by" and specify columns at same time.

for example, sql like this will just give me an error message:

load data infile '/tmp/test' into table test (class,name) fields terminated by ' ' set time=NOW() ;

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'fields terminated by ' '' at line 1

desc test;
+--------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+----------+------+-----+---------+-------+
| time | date | YES | MUL | NULL | |
| class | char(15) | YES | MUL | NULL | |
| name | char(20) | YES | MUL | NULL | |
+--------+----------+------+-----+---------+-------+

--------------Solutions-------------

Try it like this:

load data infile '/tmp/test'
  into table test
  fields terminated by ' '
  (class,name)
  set time=NOW();

! You are super cool!

Tags:
© 2018 2uzhan.com Contact