Bug #48802 missing documentation for create table if not exists select (too many columns)
Submitted: 16 Nov 2009 11:30 Modified: 23 Nov 2009 19:18
Reporter: Sven Sandberg Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Documentation Severity:S3 (Non-critical)
Version:5.1 OS:Any
Assigned to: Paul DuBois CPU Architecture:Any

[16 Nov 2009 11:30] Sven Sandberg
Description:
At http://dev.mysql.com/doc/refman/5.1/en/create-table.html , it says:

" For CREATE TABLE ... SELECT, if IF NOT EXISTS is given and the table already exists, MySQL handles the statement as follows:
[...]
 * If there is a mismatch between the number of columns in the table and the number of columns produced by the SELECT part, the selected values are assigned to the rightmost columns. For example, if the table contains n columns and the SELECT produces m columns, where m < n, the selected values are assigned to the m rightmost columns in the table. Each of the initial n – m columns is assigned its default value, either that specified explicitly in the column definition or the implicit column data type default if the definition contains no default.
"

There is no mention of what happens when the SELECT part produces too many columns. In fact, it fails with error 1241 "Operand should contain 1 column(s)"

How to repeat:
-
[16 Nov 2009 11:59] MySQL Verification Team
Thank you for the bug report.
[17 Nov 2009 14:54] Paul DuBois
That sounds like the error you get when a subquery must be a scalar subsquery but produces more than a single column.

I find I can get a different error. This, for a table with two columns:

mysql> create table if not exists t select 1,2,3,4,5;
ERROR 1136 (21S01): Column count doesn't match value count at row 1

Perhaps better to say only that if the SELECT produces more columns than are in the table, an error occurs? (Without trying to be specific about the particular error.)
[18 Nov 2009 8:24] Sven Sandberg
Paul, I agree, it's enough to say that there is an error without spelling out the error message.
[23 Nov 2009 19:18] 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 products.