Bug #60718 | Stored Function: INSERT INTO TEMPORARY TABLE; Can't reopen table | ||
---|---|---|---|
Submitted: | 1 Apr 2011 7:48 | Modified: | 1 Apr 2011 9:08 |
Reporter: | Richard Teubel | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server: Stored Routines | Severity: | S1 (Critical) |
Version: | 5.5.10, 5.0.89 | OS: | Linux |
Assigned to: | CPU Architecture: | Any | |
Tags: | FUNCTION, insert, reopen table, temporary table, temptable |
[1 Apr 2011 7:48]
Richard Teubel
[1 Apr 2011 7:49]
Richard Teubel
copy and paste file
Attachment: SP_insert_temptable.sql (application/octet-stream, text), 1.15 KiB.
[1 Apr 2011 9:08]
Valeriy Kravchuk
This is a documented limitation. Read http://dev.mysql.com/doc/refman/5.5/en/temporary-table-problems.html: "- You cannot refer to a TEMPORARY table more than once in the same query. For example, the following does not work: mysql> SELECT * FROM temp_table, temp_table AS t2; ERROR 1137: Can't reopen table: 'temp_table' This error also occurs if you refer to a temporary table multiple times in a stored function under different aliases, even if the references occur in different statements within the function." See bug #10327 (request to remove this limitation).
[11 Apr 2014 17:16]
Dillon Sadofsky
Not sure why the OP accepted this solution. Bug #10327 is unrelated to this (its regarding opening the same TEMP table more than once in a single query). Also, you referenced the manual with the following passage: "This error also occurs if you refer to a temporary table multiple times in a stored function under different aliases, even if the references occur in different statements within the function." However, this passage only says that you cannot access a TEMP table more than once under different aliases. In the above post, no aliases are used. In my mind this is a bug. The reproduction steps of selecting from a TEMP table twice with different aliases in a stored procedure are different than the above. I know this is an old case, but I actually receive this error in much stranger set of circumstances, which is what leads me to believe it is a bug. I'm going to post that in another bug because my steps are significantly different, but I'll reference this bug.