MySQL: LOAD DATA INFILE, приводящий к неверным результатам таблицы - PullRequest
0 голосов
/ 17 ноября 2018

Я пытаюсь использовать LOAD DATA INFILE для загрузки моих данных в таблицы.

Моя таблица:

Alcohol name varchar(45)
Type varchar(45)
ABV FLOAT
Brewery INT(11)
Average Price DOUBLE
Description VARCHAR(1000)

Мой CSV-файл выглядит так:

Alcohol name,Type,ABV,Brewery,Average Price,Description
Hocus Pocus,Beer,4.5,812,0,"Our take on a classic summer ale.  A toast to weeds, rays, and summer haze.  A light, crisp ale for mowing lawns, hitting lazy fly balls, and communing with nature, Hocus Pocus is offered up as a summer sacrifice to clodless days.Its malty sweetness finishes tart and crisp and is best apprediated with a wedge of orange."
Grimbergen Blonde,Beer,6.699999809,264,0,None
Widdershins Barleywine,Beer,9.100000381,779,0,None
Lucifer,Beer,8.5,287,0,None
Bitter,Beer,4,1056,0,None
Winter Warmer,Beer,5.199999809,1385,0,None
Winter Welcome 2007-2008,Beer,6,1099,0,None

etc....

Моя команда загрузки выглядит следующим образом:

LOAD DATA LOCAL INFILE '/home/leo/CS336/Tables/beers.csv' INTO TABLE Alcohol FIELDS TERMINATED BY ',' IGNORE 1 LINES; 

МусорСтол, который я получаю, выглядит так:

Alcohol name Type  ABV Brewery Average Price Description
Golden Ale  NULL    0   0   NULL NULL   
* 10.5% (2008)  NULL    0   0   NULL NULL       
* 15.5 gallon keg   NULL    0   0       NULL NULL   
* 22 oz. bottles    NULL    0   0   NULL NULL       
* 5.17 gallon keg   NULL    0   0   NULL NULL       
* 9.78% (2007)"     NULL    0   0   NULL NULL   
* Available March through August    NULL    0   0       NULL NULL   
etc...      

1 Ответ

0 голосов
/ 17 ноября 2018

Я создал таблицу на основе вашего описания (Average_Price Я добавил подчеркивание)

 create table Alcohol (
   name varchar(45), 
   Type varchar(45), 
   ABV FLOAT, 
   Brewery INT(11), 
   Average_Price DOUBLE, 
   Description VARCHAR(1000)
);

Я загрузил ваш пример файла вот так

 LOAD DATA LOCAL INFILE '/tmp/alcohol.csv' INTO TABLE Alcohol FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' IGNORE 1 LINES; 

И я думаю, что получил разумные результаты:

 `SELECT * from Alcohol;

</p> <pre>+--------------------------+------+------+---------+---------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | name | Type | ABV | Brewery | Average_Price | Description | +--------------------------+------+------+---------+---------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Hocus Pocus | Beer | 4.5 | 812 | 0 | Our take on a classic summer ale. A toast to weeds, rays, and summer haze. A light, crisp ale for mowing lawns, hitting lazy fly balls, and communing with nature, Hocus Pocus is offered up as a summer sacrifice to clodless days.Its malty sweetness finishes tart and crisp and is best apprediated with a wedge of orange. | | Grimbergen Blonde | Beer | 6.7 | 264 | 0 | None | | Widdershins Barleywine | Beer | 9.1 | 779 | 0 | None | | Lucifer | Beer | 8.5 | 287 | 0 | None | | Bitter | Beer | 4 | 1056 | 0 | None | | Winter Warmer | Beer | 5.2 | 1385 | 0 | None | | Winter Welcome 2007-2008 | Beer | 6 | 1099 | 0 | None | | | NULL | NULL | NULL | NULL | NULL | +--------------------------+------+------+---------+---------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

...