Thanks, that was extremely useful especially the date format detection. However as it's usually quite scientific data, I need to detect FLOATs, DOUBLEs and DECIMALs and the structure is not conducive to being integrated into my current framework.
Is it OK if I pilfer parts of the code and extend it for use in my app? Would be much appreciated... Cheers, Andrew -----Original Message----- From: Paul DuBois [mailto:[EMAIL PROTECTED] Sent: Tuesday 14 October 2003 19:19 To: Andrew Braithwaite; '[EMAIL PROTECTED]' Subject: Re: Auto generate MySQL schema based on a text file? At 19:05 +0100 10/14/03, Andrew Braithwaite wrote: >Hi, > >Does anyone know of a perl module or other code that can look at a text >file (CSV, tab-delim etc..) of data and determine a MySQL table >definition from it? > >The data may or may not have a set of column headers as the first line. You can use the guess_table.pl utility that's part of the software distribution that accompanies MySQL Cookbook. The distribution is available at: http://www.kitebird.com/mysql-cookbook/ Follow the Downloads link, grab the recipes distribution, unpack it, and look in the transfer directory. It requires tab-delimited data. For other formats, you may be able to use the cvt_file.pl util that's in the same directory to convert them to tab-delimited. % guess_table.pl --help Usage: guess_table.pl [options] [data_file] Options: --help Print this message --labels, -l Interpret first input line as row of table column labels (default = c1, c2, ...) --lower, --upper Force column labels to be in lowercase or uppercase --quote-names Quote table and column names with `` characters (in case they are reserved words) --report , -r Report mode; print findings rather than generating a CREATE TABLE statement --table=tbl_name, -ttbl_name Specify table name (default = t) > >I would appreciate it greatly if anyone could give me any pointers to >existing stuff as I have to implement this function (and I don't >particularly like spending my time painfully churning out regexps if >it's not absolutely necessary!! :) > >Cheers, > >Andrew > >SQL, Query -- Paul DuBois, Senior Technical Writer Madison, Wisconsin, USA MySQL AB, www.mysql.com Are you MySQL certified? http://www.mysql.com/certification/ -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]