Solved

MySQL query to load data from file

Posted on 2014-01-27
1
451 Views
Last Modified: 2014-02-03
Hi,
I have the following mysql query written in a java spring application to load data from file
into the table :

"LOAD DATA LOCAL INFILE '"+ dumpFile.replace("\\", "\\\\") +
                        "' REPLACE INTO TABLE "+ table
                        +" FIELDS TERMINATED BY '\\t' LINES TERMINATED BY '\\n'"+
                        " (origin, destination, price, dep_date, arrival_date, supplier, search_type)";

Now the table structure to which the data is being loaded have an extra column called key.
And that extra column is key = origin#destination#dep_date
but if search_type='R'
then key = origin#destination#dep_date#arrival_date

Now i need to insert this key too.
How do i modify my query to do this ?

Thanks
0
Comment
Question by:Rohit Bajaj
1 Comment
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 39814304
you add this expression at the end of your statement:
SET key = CONCAT(origin, '#', destination ,'#', dep_date) 

Open in new window



references:
http://dev.mysql.com/doc/refman/5.1/en/load-data.html
http://dev.mysql.com/doc/refman/5.1/en/string-functions.html#function_concat

hope this helps
0

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
I have been using r1soft Continuous Data Protection (http://www.r1soft.com/linux-cdp/) for many years now with the mySQL Addon and wanted to share a trick I have used several times. For those of us that don't have the luxury of using all transact…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now