Solved

MySQL query to load data from file

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

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://…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

733 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