If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Import data file in "var1=data1 var2=data2" format

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-23-06, 23:08
RickW RickW is offline
Registered User
 
Join Date: Feb 2004
Posts: 29
Question Import data file in "var1=data1 var2=data2" format

I have a sample file that contains entries like:

age=24 gender=male height=63 weight=180 eyecolor=blue haircolor=blonde
age=21 gender=female height=52 weight=140 eyecolor=hazel haircolor=brown
age=27 gender=female height=48 weight=127 eyecolor=brown haircolor=black

etc.

I know how to handle comma or tab delimited data, but I'm not sure what this format is called. I have a table setup with each variable as a column. In some cases, I may have a sample file that only has some of these variables, or maybe more, and may not have them in the same order. So I cannot rely on the position of this data.

How do I tokenize this, and import it into my table? What is this format called, so I can look up a reference going forward?
Reply With Quote
  #2 (permalink)  
Old 09-23-06, 23:26
dbmab dbmab is offline
Registered User
 
Join Date: Apr 2006
Location: Denver, Co. USA
Posts: 240
I don't know if there is an official name, but I would refer to this as "key/value."
Reply With Quote
  #3 (permalink)  
Old 09-23-06, 23:58
RickW RickW is offline
Registered User
 
Join Date: Feb 2004
Posts: 29
Quote:
Originally Posted by dbmab
I don't know if there is an official name, but I would refer to this as "key/value."
Thanks. With that tidbit, I'm starting to search for "key/value metadata". My results are a closer match than what I was getting before, but I still haven't gotten an example of how to import this into mysql.

My instincts tell me I should probably import each line into a temporary array by tokenizing the key/value pairs by the spaces. Then I would parse the array again to be break the entry into a table, using the = as the delimeter. Then a loop would put each value into each column based on the key (if it exists). Seems like an inefficent brute force though...
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

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