Thursday, 22 August 2013

Import single csv file with one data field going to separate table

Import single csv file with one data field going to separate table

I know this one is probably a long shot but I thought I would at least
ask. Say I have a csv file with a list of Products with the following 4
columns/data fields (Product ID, Name, Alias, UOM) that I would like to
import into a database that has 2 tables. One table is the Product table
(Product ID, Name, UOM), second table is Product Alias table with these 2
columns(Product ID, Alias), where each Product ID may have 0 to many alias
names. Is there any way I could treat the Alias column different by the
fact it has a different separator between the comma's like ";" or a period
"." to separate the 0 to many alias names for a given Product ID.
Therefore during the csv import, when it gets the 3rd comma, it would
import that data into this 2nd table but import a new record with
repeating Product ID's for as many alias names are in that comma field.
Hopefully I explained that well enough, let me if I didn't. I'm more
interested in the possible processing of doing this regardless of what
code that is being using but python would be the preferred route.
ProductID, Name, Alias, UOM
122, Widget1, W1;Wid1;Wt1, Each
123, Widget2, , Each
124, Widget3, W3;Wt3, Each

No comments:

Post a Comment