[SPAM] Re: [mod_python] SQL question

Deron Meranda deron.meranda at gmail.com
Wed Feb 1 12:56:24 EST 2006


Unfortunately there is no portable way to do this--DESCRIBE is a
proprietary verb.  The official ISO standard SQL way is to query the
INFORMATION_SCHEMA pseudo-tables.  Such as

 select KU.COLUMN_NAME
   from INFORMATION_SCHEMA.KEY_COLUMN_USAGE KU
   where KU.TABLE_NAME = 'mytable'
        and KU.CONSTRAINT_NAME = 'PRIMARY'
   order by KU.ORDINAL_POSITION;

This works in the PySybase adapter (which is also used to connect
to MS SQLServer), and also MySQL 5.   See

http://dev.mysql.com/doc/refman/5.0/en/information-schema.html

But it's still not completely portable, because so many DB
vendors don't yet support the standard INFORMATION_SCHEMA.
Oracle tends to use the DESCRIBE way.  In MySQL < 5, you
have SHOW (like SHOW CREATE TABLE).

Fortunately with Python, at least part of the meta-data is
available in a standardized way using the DBAPI.

Perhaps you should check up on what the Python DB_SIG group
says, or is doing.  If it's not in the works, or rejected, perhaps
you can suggest a Pythonic standard way to query meta data.
--
Deron Meranda



More information about the Mod_python mailing list