Update a field only if currently null
I have a users table with a field called mainListId which is null by default. whenever a user creates a new list, I need to check if *mainListId *is null, and if so, I update this field to contain the new list id.
Is it somehow posibble to update *mainListId * only if it's currently null, so that I won't have to make another query just to check if it's currently null or not?
6 Replies
What type of column is mainListId? is it an array in PG?
the mainListId field is simply an integer which is a foreign key to the lists table
So how do you handle it if mainListId is not null?
In that case I don't need to update *mainListId * (because this is not the first list the user has created)
Solution
In that case it's pretty easy:
that's cool, thanks a lot!