checking presence of table columns in mysql

David A. Sinck plug-discuss@lists.plug.phoenix.az.us
Tue, 11 Feb 2003 09:49:23 -0700


\_ SMTP quoth Lynn David Newton on 2/10/2003 21:42 as having spake thusly:
\_
\_ 
\_   Mike> /_Does anyone know of a SQL based way to check for
\_   Mike> /_the existence of a particular column by name?
\_ 
\_   Mike> Hmmm, have you tried looking in the array:
\_ 
\_   Mike> my $names = $sth->{NAME} ;
\_ 
\_ Your suggestion is a bit minimalist, but was sufficient
\_ for me to discover that this works:
\_ 
\_   $sth = $dbh->prepare("select * from tablename");

Neigh, neigh, I say!

Think about the evil bastardness of that simple statement when you
have 1M rows.  You ask the database for ALL data?  Probably not the
turn around time you want.

Solutions:

* add ' limit 1 ' to the statement 
   mysql only afaik, might break if no rows
* add ' where 1 = 0 ' to the statement 
   don't think mysql supports this, but oracle does (or did).  Not very many
   rows satisfy that condition, so the result size is small, but
   provides all the rows because of the '*'
* go with Brian Tafoya's solution 
   I've done this before
* also try groking the results of "desc $table"

David