On Sat, Dec 6, 2008 at 20:23, hotkitty <[EMAIL PROTECTED]> wrote: > Hi, > > I am using DBI to add a column to my existing table, goodtable. W/ a > phpmyadmin I can add a column w/ a numeric or nonnumeric label. Using > perl DBI, I can only add a column w/ a nonnumeric label, as follows: > > $dbh->do("ALTER TABLE goodtable ADD testname VARCHAR( 250 ) NULL"); > -------->is a non-numeric column label and works fine. > > However, changing "testname" to a number results in an error...... > $dbh->do("ALTER TABLE goodtable ADD 546 VARCHAR( 250 ) NULL"); > -------->is a numeric column label and throwsback the following > error: > > DBD::mysql::db do failed: You have an error in your SQL syntax; check > the manual that corresponds to your MySQL server version for the right > syntax to use near '451 VARCHAR( 250 ) NULL' > > Again, everything works fine doing it in a non-perl way. I've tried > using quotes, escape characters, $sql = $dbh->quote($value), etc. > (Obviously, I could do this in a web interface but this project > requires creating columns on the fly, so to speak, so I must use perl > for this.) snip
To my knowledge MySQL doesn't allow numeric only column names: mysql> alter table foo add column 123 int; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '123 int' at line 1 If phpadmin is letting you add them then it is most likely adding a different name and showing you a numeric label. Try checking the actual database to see what the column is named. Also, I must warn you that a numeric column name is an incredibly bad idea (I would go so far as to say any numbers at all in a column name is generally* a sign off a bad design**). Column names should reflect their contents and numbers alone just don't have the descriptive power. * the best counter-example I can think of is something like "supports_sql92" where the number is a part of the term, but in my experience those cases are rare. ** here I am mostly talking about things like address1, address2, etc. This is better handled with another table with a one-to-many relationship with the first table. -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/