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?
Solution
In that case it's pretty easy:
db.update(users).set({ mainListId: providedId }).where(and(eq(users.id, theIdOfTheUserToUpdate), isNull(users.mainListId)))
Was this page helpful?