Is this a bug in MySQL (5.1.41-community) --
CREATE TEMPORARY TABLE zztest (stuff varchar(20) NULL)
INSERT INTO zztest
SELECT
'test'
FROM (
select '1' as testcol
union
select null
) a
WHERE **IF(a.testcol IS NULL,'',a.testcol)** IS NOT NULL
This is a simplified query. The IF expression between the **'s was supposed to be bolded. It comes from a dynamic query, where The IF expression was innocently placed into a query.
The select by itself works. When combined with the insert statement it did not work. The inner select is designed to show that the temporary table created can have nulls in the column being checked.
The issue was "fixed" by replacing the IF with an IFNULL(a.testool, '')
Some other replacesments fail too (whereas the selects by themselves work):
1 IF (a.testcol, '', a.testcol)
2 IF (a.testcol, '', '')
3 IF ('', '', '')
Does this bug exist in other version of MySQL?
Edit -- Results of query with select:
Message: Error Code: 1292. Truncated incorrect INTEGER value: ''
The results it is supposed to have are that two 'test' strings are input into the zztest table.
Edit -- I tried it out again after about 2 hours. The last two statements "worked" (remember to plug them into the query above..). The first replacement statement failed. Then numbers 2 and three failed again.
So it looks like statement 1 is the culprit (and the original, it errors out now..).. And perhaps some kind of bad state exists where statements that produce the same intermediary results also fail.
So a follow up question then is -- is there a way to make sure that the query is reset?
Just after I tried to execute the query in a new connection, workbench crashed.. Related?
edit -- found that an explicit cast works:
IF (a.testcol, cast('' as char), cast('' as char))
So I've found my way around it. The question is -- why would '' (with anything within the quotes) be interpreted as an INTEGER? I even got it to be interpreted as a DOUBLE by concat-ing ''.
And why did it work sometimes, and not others? <-- this part sucks the mostess.