checking presence of table columns in mysql

Lynn David Newton plug-discuss@lists.plug.phoenix.az.us
Tue, 11 Feb 2003 06:51:20 -0700


  >> Since there seems to be some mysql expertise on
  >> the list: Does anyone know of a SQL based way to
  >> check for the existence of a particular column by
  >> name? This came up in work today. I've never been
  >> able to do it. I'm not so sure it's possible.

  George> Not purely sql, but close:
  George> mysql -uwhomever -ppassword -hhost database -e "describe table" | grep
  George> fieldnamee

  George> For example:
  George> $ mysql -uuser -ppassword -haaron database -e "describe day" | grep -c
  George> create_ts
  George> 1

Right, I've done that. That's something that's simple
in the shell. I was looking for something that works
through Perl. Yeah, I could run system("blah blah") and
munge the data, but that's so primitive.

As it turns out, the statement handle attributes in DBI
inherit all the metadata one is likely to be interested
in: number of fields, field names, field types, etc.
That's the sophisticated way to go.

Thanks for your suggestion.

-- 
Lynn David Newton
Phoenix, AZ