I’m working with a temporary table in a MySQL stored procedure and running into a weird issue. When I select all records without any conditions, the data looks perfect. But when I try to filter using a WHERE clause on a specific column, it acts like the values are NULL even though I can clearly see the data is there.
Here’s my temp table setup:
DROP TABLE IF EXISTS temp_records;
CREATE TEMPORARY TABLE temp_records (item_id BIGINT, status_code INT NOT NULL);
Inserting data like this:
INSERT IGNORE INTO temp_records (item_id, status_code)
SELECT item_id, status_code FROM main_records;
When I check all data:
SELECT * FROM temp_records;
I get:
# item_id, status_code
'5', '200'
Looks good right? But then this query returns nothing:
SELECT * FROM temp_records WHERE status_code = 200;
And when I check again:
SELECT item_id, status_code FROM temp_records;
Now I see:
# item_id, status_code
5, null
I tried debugging with:
SELECT DISTINCT item_id, status_code,
status_code IS NULL,
status_code = '',
CHAR_LENGTH(status_code),
HEX(status_code)
FROM temp_records;
Result shows everything as NULL. The INSERT happens inside dynamic SQL within the stored procedure. Anyone know what could cause this behavior where data appears initially but then becomes NULL?