Jump to content

Data Import


smti

Recommended Posts

Hello,

 

I wrote a bash script to import some data from a CSV file. The code is as follows:

Load Data local infile '/home/<USERNAME>/tstProducts.csv' into table tstProducts fields terminated by ',' enclosed by '"' lines terminated by '\n' (Name, Type, Brand, Description, ABV, TimesAvailable, Image, Website) Ignore 1 Lines;

When I run the bash script I get the following error: syntax error near unexpected token `('

 

Any thoughts on why this may be occurring? I checked my code against a sample and everything looks correct. Any help or insight you can provide would be greatly appreciated!

 

 

-smti

Edited by smti
Link to comment
Share on other sites

The IGNORE should come before the column list

 


LOAD DATA [LOW_PRIORITY | CONCURRENT] [LOCAL] INFILE 'file_name'
[REPLACE | IGNORE]
INTO TABLE tbl_name
[PARTITION (partition_name,...)]
[CHARACTER SET charset_name]
[{FIELDS | COLUMNS}
[TERMINATED BY 'string']
[[OPTIONALLY] ENCLOSED BY 'char']
[ESCAPED BY 'char']
]
[LINES
[sTARTING BY 'string']
[TERMINATED BY 'string']
]
[iGNORE number {LINES | ROWS}]
[(col_name_or_user_var,...)]
[sET col_name = expr,...]

Link to comment
Share on other sites

I also tried this with the same result:

LOAD DATA LOCAL INFILE '/home/jalewellyn/tstProducts.csv' INTO TABLE tstProducts FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\r\n' IGNORE 1 LINES (Name, Type, Brand, Description, ABV, TimesAvailable, Image, Website);
Link to comment
Share on other sites

As for getting a bash error, you need to escape the braces otherwise everything between them it will be treated by the parser as a group of commands. 

 

Try,

LOAD DATA LOCAL INFILE '/home/jalewellyn/tstProducts.csv' INTO TABLE tstProducts FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\r\n' IGNORE 1 LINES \(Name, Type, Brand, Description, ABV, TimesAvailable, Image, Website\)
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.