0

I can't seem to figure out how to get mysql to store an int value as 'null', instead it continues to give it a zero based value. In my case zero has a meaning to the app. Anybody know how I can store actual nulls?

10
  • possible duplicate of Insert NULL value into INT column Commented Sep 14, 2014 at 16:35
  • Or this question Commented Sep 14, 2014 at 16:36
  • No that is very different. I can insert a null value, however it converts it to zero. I can't have it converting to zero and my column is setup to accept nulls. Commented Sep 14, 2014 at 16:37
  • Define converts it to 0? In the database? Commented Sep 14, 2014 at 16:39
  • When I run this sql statement UPDATE my_table SET field1=null WHERE field1 = 0; The values remain zero. I can not get the database to show null, it only shows zero and they mean two completely different things. Commented Sep 14, 2014 at 16:41

2 Answers 2

2

I'm on my mobile phone so I can't test this... Also this is too long to be a comment... first thing try selecting the rows in question.. Then if they arent returned try updating a select when the rows are equal to 0.

Maybe it is null but you have a setting in mysql workbench that shows a 0 instead

SELECT id, field1 
FROM table 
WHERE field1 IS NULL;

If that doesn't return the rows then do this

SELECT id, field1
FROM table
WHERE field1 =0

If that does then try an update with these exact rows

UPDATE table t,
(   SELECT id, field1
    FROM table
    WHERE field1 = 0
) temp
SET t.field1 = NULL
WHERE t.id = temp.id

Hope that is helpful

Sign up to request clarification or add additional context in comments.

2 Comments

I have absolutely no clue what I did, but for some reason, it is finally working now. Thank You John.
Sure thing... Interesting issue you had
1

You just write null:

mysql> CREATE TABLE t (i INT);
Query OK, 0 rows affected (0.15 sec)

mysql> INSERT INTO t VALUES (null);
Query OK, 1 row affected (0.09 sec)

mysql> SELECT * FROM t;
+------+
| i    |
+------+
| NULL |
+------+
1 row in set (0.00 sec)

mysql> SELECT * FROM t WHERE i IS NULL;
+------+
| i    |
+------+
| NULL |
+------+
1 row in set (0.03 sec)

3 Comments

believe me I did, I have no idea what was causing this issue.
I did up above under my question
But it's working now, it could have been a workbench glitch for all I know.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.