Is there a way to set a column to NULL using $wpdb->update();?
When I attempt to, WordPress attempts to typecast that column to a float, which converts NULL to 0.
I’ve checked the core code and inside of $wpdb->update(), the $format parameter is only expecting %s, %f, and %d. I went so far as to set $wpdb->field_types['myCol'] to 'NULL', but both only serve to break $wpdb->update()‘s query (interestingly enough, it shifts the values for each column over after the NULL).
There is a related question here, but that answer only deals with INSERT, not UPDATE.
From a data integrity standpoint, NULL is very important for this column, so I have to be able to set it as such when necessary.
As you yourself note, the
$formatparameter is only expecting%s,%f, and%d. The whole thing will get passed throughpreparewhich also doesn’t take anullformat specifier because it basically accepts the same format specifiers that are accepted by(v)(s)printfbut without the argument swapping. You can’t passNULLthroughupdate. You have the same choices as mentioned in the post suggested as a possible duplicate, and in essence it is.updatefunction. Write your own SQL and use it with$wpdb->query. If you are dealing with your own tables that should be fine.$wpdbwith a drop-in.