How can I generate sql inserts from pipe delimited data?

Posted by user568866 on Stack Overflow See other posts from Stack Overflow or by user568866
Published on 2011-01-09T15:40:37Z Indexed on 2011/01/09 15:53 UTC
Read the original article Hit count: 272

Filed under:

Given a set of delimited data in the following format:

1|Star Wars: Episode IV - A New Hope|1977|Action,Sci-Fi|George Lucas
2|Titanic|1997|Drama,History,Romance|James Cameron

How can I generate sql insert statements in this format?

insert into table 
   values(1,"Star Wars: Episode IV - A New Hope",1977","Action,Sci-Fi","George Lucas",0);
insert into table 
   values(2,"Titanic",1997,"Drama,History,Romance","James Cameron",0);

To simplify the problem, let's allow for a parameter to tell which columns are text or numeric. (e.g. 0,1,0,1,1)

© Stack Overflow or respective owner

Related posts about elisp