Computer Webmaster Gaming Console Graphics Forum

Welcome to the Computer Webmaster Gaming Console Graphics Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

MK PitStop Main Earn $25 Earn Money Posting Extras Members Blogs Image Hosting User Pages
Go Back   Computer Webmaster Gaming Console Graphics Forum > Webmaster Forum > Website Coding > Database
Register FAQ/Rules Become A V.I.P. Member Search Today's Posts Mark Forums Read

Database Database problems or need to ask a question? maybe something to do with sql injections or a database software question. Database topics cover MySQL, PostgreSQL, Oracle, SQL Server or anything else related to databases.

Google
Closed Thread
 
LinkBack Thread Tools Display Modes
Old 07-01-2007, 9:35 PM   #1
stefaan.lhermitte@agr.kuleuven.ac.be
 
stefaan.lhermitte@agr.kuleuven.ac.be's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Complex LOAD DATA INFILE

Dear mysql-ians,

I am using mysql 5.0 and I want to load a huge txt-file in my database.
My text file (file.txt) looks like:

col1 col2 col3 ... col200
col1 col2 col3 ... col200
....
col1 col2 col3 ... col200

I now want it to import in a table t1 with two columns (col_nr,
col_val) where col_nr is the number of column (e.g. 2 for col2, 46 for
col46) and col_val are the effective values in my txt-file at the
different columns. The problem is that col_nr is not in the "file.txt"
so I have to assign based on the field number.

I am looking at the LOAD DATA INFILE command, but in the help file I
did not find an answer to my question. I was hoping to do it with:

LOAD DATA INFILE 'file.txt'
INTO TABLE t1
(col_val)
SET col_nr = "how do I do this";

Does anyone has any suggestions or tips to do it differently (with php
perhaps)?

Thanks in advance!

Stef

 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Advertisements
Old 07-01-2007, 9:35 PM   #2
Paul Lautman
 
Paul Lautman's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Complex LOAD DATA INFILE

stefaan.lhermitte@agr.kuleuven.ac.be wrote:
> Dear mysql-ians,
>
> I am using mysql 5.0 and I want to load a huge txt-file in my
> database. My text file (file.txt) looks like:
>
> col1 col2 col3 ... col200
> col1 col2 col3 ... col200
> ...
> col1 col2 col3 ... col200
>
> I now want it to import in a table t1 with two columns (col_nr,
> col_val) where col_nr is the number of column (e.g. 2 for col2, 46 for
> col46) and col_val are the effective values in my txt-file at the
> different columns. The problem is that col_nr is not in the "file.txt"
> so I have to assign based on the field number.
>
> I am looking at the LOAD DATA INFILE command, but in the help file I
> did not find an answer to my question. I was hoping to do it with:
>
> LOAD DATA INFILE 'file.txt'
> INTO TABLE t1
> (col_val)
> SET col_nr = "how do I do this";
>
> Does anyone has any suggestions or tips to do it differently (with php
> perhaps)?
>
> Thanks in advance!
>
> Stef


Each row in the text document has different values for the column number,
yes? So the table will have lots of rows with col_nr = 3 and different
values in col_var? Also how are the columns delimited in the text file?


 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Old 07-01-2007, 9:35 PM   #3
stefaan.lhermitte@agr.kuleuven.ac.be
 
stefaan.lhermitte@agr.kuleuven.ac.be's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Complex LOAD DATA INFILE

Paul Lautman schreef:

> Each row in the text document has different values for the column number,
> yes? So the table will have lots of rows with col_nr = 3 and different
> values in col_var?


Indeed my table has 270 columns and the values for every field for
every row are different. Below you can find a small extract of my
file.txt (with only 3 columns and 8 rows).

38 61 1
35 64 1
35 64 1
41 59 0
39 61 0
42 58 0
28 72 0
36 64 0

> Also how are the columns delimited in the text file?


My text-file is organised in a fixed length fomat for every field (as
you can see in the extract).

I also see that the SET command is only valid from MySQL 5.0.3 and I
just donwloaded 5.0.21 so I assume the SET will not work anyway. Do you
have other suggestions?

For your information: my text file contains al lot of info (270 fields
X 2M records).

Thanks in advance,
Stef

 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Old 07-01-2007, 9:35 PM   #4
strawberry
 
strawberry's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Complex LOAD DATA INFILE

Just to clarify. As I understand it, you want to take the file and
rearrange it like this (I'm using your sample data):

COL_NR | VALUE
1 | 38
1 | 35
1 | 35
1 | 41
1 | 39
1 | 42
1 | 28
1 | 36
2 | 61
2 | etc, etc.

So maybe your table should have a 3rd column, or, more precisely a
'1st' column which will hold the key to the table - like this:

id | col_nr | value
1 | 1 | 38
2 | 1 | 35
3 | 1 | 35
4 | 1 | etc, etc.

As for getting the data into the table, I'm a bit stuck. I think that
the PHP solution might be the way to go - with a loop that counts to
270 for instance.

 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Old 07-01-2007, 9:35 PM   #5
Paul Lautman
 
Paul Lautman's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Complex LOAD DATA INFILE

stefaan.lhermitte@agr.kuleuven.ac.be wrote:
> Paul Lautman schreef:
>
>> Each row in the text document has different values for the column
>> number, yes? So the table will have lots of rows with col_nr = 3 and
>> different values in col_var?

>
> Indeed my table has 270 columns and the values for every field for
> every row are different. Below you can find a small extract of my
> file.txt (with only 3 columns and 8 rows).
>
> 38 61 1
> 35 64 1
> 35 64 1
> 41 59 0
> 39 61 0
> 42 58 0
> 28 72 0
> 36 64 0
>
>> Also how are the columns delimited in the text file?

>
> My text-file is organised in a fixed length fomat for every field (as
> you can see in the extract).
>
> I also see that the SET command is only valid from MySQL 5.0.3 and I
> just donwloaded 5.0.21 so I assume the SET will not work anyway. Do
> you have other suggestions?
>
> For your information: my text file contains al lot of info (270 fields
> X 2M records).
>
> Thanks in advance,
> Stef


When I used to need to do this sort of things back when I worked for IBM, I
would always turn to PIPELINEs to change that file into one that would load
into the database (actually if putting into DB/2 I would use the PIPELINEs
DB/2 device driver to maipulate the data and feed it straight into the
database using INSERT statements created in the PIPELINE).

Datamystic's .com TextPipe product enables you to do this on a PC.

However, even without PIPELINEs, I would still be tempted to preprocess your
file using whatever came to hand (REXX, VB, VBA, PHP, PERL, ...) to make it
look like:

1,38
1,35
1,35
1,41
1,39
1,42
1,28
1,36
2,61
2,64
2,64
2,59
2,61
2,58
2,72
2,64
3,1
3,1
3,1
3,0
3,0
3,0
3,0
3,0


Which could then be loaded simply into the database. Is every field the same
length, or do they vary and is there always at least one space between the
fields, or do some run into each other?


 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Old 07-01-2007, 9:35 PM   #6
Bill Karwin
 
Bill Karwin's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Complex LOAD DATA INFILE

stefaan.lhermitte@agr.kuleuven.ac.be wrote:
> I also see that the SET command is only valid from MySQL 5.0.3 and I
> just donwloaded 5.0.21 so I assume the SET will not work anyway. Do you
> have other suggestions?


5.0.21 is a later release than 5.0.3, and should be a superset of the
features in 5.0.3. See the sequence of releases here:
http://dev.mysql.com/doc/refman/5.0/en/news-5-0-x.html

Regards,
Bill K.
 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Old 07-01-2007, 9:35 PM   #7
Bill Karwin
 
Bill Karwin's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Complex LOAD DATA INFILE

stefaan.lhermitte@agr.kuleuven.ac.be wrote:
> Dear mysql-ians,
>
> I am using mysql 5.0 and I want to load a huge txt-file in my database.
> My text file (file.txt) looks like:
>
> col1 col2 col3 ... col200
> col1 col2 col3 ... col200
> ...
> col1 col2 col3 ... col200
>
> I now want it to import in a table t1 with two columns (col_nr,
> col_val) where col_nr is the number of column (e.g. 2 for col2, 46 for
> col46) and col_val are the effective values in my txt-file at the
> different columns. The problem is that col_nr is not in the "file.txt"
> so I have to assign based on the field number.


One solution would be to do it in two steps. Create a new table with
200 columns, load the data from the file, and then use SQL to copy the
values fom that table to the two-column destination table.

CREATE TABLE t1_wide( col1 CHAR(3), col2 CHAR(3), col3 CHAR(3), ...
col200 CHAR(3));
LOAD DATA INFILE INTO TABLE t1_wide FIELDS TERMINATED BY ' ';
INSERT INTO t1 SELECT 1, col1 FROM t1_wide;
INSERT INTO t1 SELECT 2, col2 FROM t1_wide;
INSERT INTO t1 SELECT 3, col3 FROM t1_wide;
....
INSERT INTO t1 SELECT 200, col200 FROM t1_wide;

Another solution would be to write a custom application in your favorite
programming language to parse the text file and execute the appropriate
INSERT statements to load the data.

Regards,
Bill K.
 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Featured Websites
Free Space
Free Space
Free Space Free Space
Closed Thread
Tags: , , ,




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
load data infile - deleted, warnings, skipped roch77@gmail.com Database 2 07-01-2007 9:29 PM
Load Data Infile question bradfordh@gmail.com Database 3 07-01-2007 7:31 PM
LOAD DATA INFILE - need to escape characters? Could use some help... Job Database 0 07-01-2007 6:40 PM
LOAD DATA is it transactional ? Tony Database 2 07-01-2007 6:27 PM
Pass an argument to Load data Infile Dale Database 0 05-31-2007 8:42 PM


Featured Websites




All times are GMT +1. The time now is 12:09 AM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.0.0
Cheap Computers
MK PitStop Copyright 2005 - 2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98