Solved

MySQL query to load data from file

Posted on 2014-01-27
1
466 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 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Foreword This is an old article.  Instead of using the MySQL extension that was used in the original code examples, please choose one of the currently supported database extensions instead.  More information is available here: MySQLi / PDO (http://…
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

695 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