My SQL Dump

MySQL musings by a self professed MySQL Geek

Previous Entry Share Next Entry
More MySQL idiocy, or "Why does INFORMATION_SCHEMA fail to show information about TEMPORARY tables?"
swanhart
This problem is "documented" in two bugs:
http://bugs.mysql.com/bug.php?id=36073
http://bugs.mysql.com/bug.php?id=20001

Why in the world is this just a "documentation fix"? There have been a number of occasions when I've tried to write generic stored procedures that might want to analyze information about temporary tables. For instance, given a SELECT statement, I want to determine what datatypes each select clause produces. A fairly straightforward way to do this might be to run a "create temporary table xyz as (SELECT ... LIMIT 0), to produce an empty temporary table to analyze. This doesn't work however, because there isn't any information on xyz in the information schema! Worse, SHOW statements don't work as a PREPARED STATEMENT so there isn't any way to determine this information in a programmatic manner!

mysql> create database if not exists test;
Query OK, 0 rows affected, 1 warning (0.02 sec)

mysql> use test;
Database changed

mysql> CREATE TEMPORARY TABLE x
    -> (z int) engine=MYISAM;
Query OK, 0 rows affected (0.00 sec)

mysql> SELECT * FROM test.x;
Empty set (0.00 sec)

mysql> SELECT * 
    -> FROM INFORMATION_SCHEMA.TABLES 
    -> WHERE TABLE_NAME='x';
Empty set (0.01 sec)

You are viewing swanhart