0

I have added ENUM column in my table, and all my rows that are already existing have got a NULL value. The only problem is that I don't get how to select and upgrade them to what I need.

I've tried something like UPGRADE users Status='User' where Status=NULL and other options like "... where Status='' " but none of these bring me the solution.

I want to change every NULL value to 'User'.

1
  • 1
    Is 'User' one of the enumerated values? If it is then do an UPDATE. Commented Jul 1, 2019 at 17:43

2 Answers 2

4

NULL is a special value, in pretty much any normal comparison, if NULL is involved the result is NULL; which is not TRUE, which means effectively FALSE. When comparing for NULL you need to is x IS NULL, or x IS NOT NULL.

That said, I generally recommend avoiding MySQL's ENUM data type. Adding new values involves ALTER TABLE, which involves rebuilding the table. They also do not "play nice" with a lot of libraries used to connect to databases; and have weird semantic in general. You're usually much better off with a lookup table using standard data types.

Also, the statement type you're looking for is UPDATE, there is no "UPGRADE".

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

Comments

3

Try:

UPDATE users
SET    Status = 'User'
WHERE  Status IS NULL;

This is because NULL is a special value. Conceptually, NULL means “a missing unknown value” and it is treated somewhat differently from other values. To test for NULL, use the IS NULL and IS NOT NULL operators.

Comments

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.