Bug #13836 Why 'CREATE TABLE' is not a preparable statement in SQL?
Submitted: 7 Oct 2005 11:34 Modified: 3 Nov 2005 0:37
Reporter: Valeriy Kravchuk Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Documentation Severity:S3 (Non-critical)
Version:5.0.15-rc-BK OS:Linux (Linux, Windows)
Assigned to: Paul DuBois CPU Architecture:Any

[7 Oct 2005 11:34] Valeriy Kravchuk
Description:
Quote from the manual (http://dev.mysql.com/doc/mysql/en/c-api-prepared-statements.html):

"The following statements can be used as prepared statements: CREATE TABLE, DELETE, DO, INSERT, REPLACE, SELECT, SET, UPDATE, and most SHOW statements. Other statements are not yet supported."

Another quote:

"SQL syntax for prepared statements is based on three SQL statements:

PREPARE stmt_name FROM preparable_stmt;
...
preparable_stmt is either a string literal or a user variable that contains the text of the statement. The text must represent a single SQL statement, not multiple statements. Within the statement, ‘?’ characters can be used as parameter markers to indicate where data values are to be bound to the query later when you execute it."

So, because there are no other explanations on what statements are preparable, I think, CREATE TABLE is one of them. But look, for SELECT it works:

mysql> prepare stmt from 'select ?';
Query OK, 0 rows affected (0,19 sec)
Statement prepared

mysql> set @b='abc';
Query OK, 0 rows affected (0,00 sec)

mysql> execute stmt using @b;
+-----+
| ?   |
+-----+
| abc |
+-----+
1 row in set (0,00 sec)

And the following does no work:

mysql> prepare stmt2 from 'create table ? (c1 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 '? (c1  int)' at line 1
mysql> select version();
+-----------+
| version() |
+-----------+
| 5.0.15-rc |
+-----------+
1 row in set (0,00 sec)

Why? It is at least a request to the Documentation team to describe it, if it is an intended behaviour (I believe, it is not)

Verified on ChangeSet@1.2019, 2005-10-06 03:49:14+02:00, kent@mysql.com

How to repeat:
use test;
prepare stmt2 from 'create table ? (c1 int)';

Suggested fix:
Handle all preparable statements properly and update documentation.
[8 Oct 2005 15:51] Sergei Golubchik
Documentation issue. " marker can be used anywhere where an expression is allowed.
table name in the create table is not such a place.
[3 Nov 2005 0:37] Paul DuBois
Thank you for your bug report. This issue has been addressed in the
documentation. The updated documentation will appear on our website
shortly, and will be included in the next release of the relevant
product(s).