?
Solved

MySQL query to load data from file

Posted on 2014-01-27
1
Medium Priority
?
474 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

771 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