Importing headers

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • torjon@NOSPAMnterport.net

    #1

    Importing headers

    I have a text file with 180 headers.
    Is it possible to import this file into mysql where mysql will
    automatically create the table with column headings from the headers
    (as sql server and access do?)

    In case that doesn;t work, how can I create the table and past the
    header names into th command line, or use a text file to impoprt the
    headers in somehow?

    Last question, am I gonna be sitting there doing a 160+ field create
    table statement? Please say no.
  • Bill Karwin

    #2
    Re: Importing headers

    torjon@NOSPAMnt erport.net wrote:[color=blue]
    > I have a text file with 180 headers.
    > Is it possible to import this file into mysql where mysql will
    > automatically create the table with column headings from the headers
    > (as sql server and access do?)[/color]

    I can't find an option like this in the docs for the mysqlimport tool or
    its statement equivalent, LOAD DATA INFILE. It seems from the docs that
    you must have a table created before you can import into it from a text
    file. I don't know if another tool exists to do what you want.
    [color=blue]
    > In case that doesn;t work, how can I create the table and past the
    > header names into th command line, or use a text file to impoprt the
    > headers in somehow?[/color]

    If it were me, I'd write a Perl script to parse the headers in the text
    file, and generate an appropriate CREATE TABLE statement from them.
    For instance:

    head -1 textfile | perl -ane 'print "CREATE TABLE myTable (\n\t",
    join(",\n\t", map("$_ VARCHAR(100)", @F)), "\n);\n";'

    Edit the resulting CREATE TABLE statement if you want to change some of
    the column defs, and then run the statement using the mysql tool.

    Then use mysqlimport to load the rest of the data from the file into the
    table.

    Regards,
    Bill K.

    Comment

    Working...