How to work with NULL values in CARTO datasets
- To replace all
NULLvalues in a column you can use the
COALESCEPostgreSQL function. This replaces
nullwith 0, because
UPDATE table_name SET column = COALESCE(column, 0)
If your column type is string, make sure to enclose the second COALESCE argument in single quotes.
- You can do the opposite with
NULLIF, thus replacing non-null values with
UPDATE populated_places SET pop_max = NULLIF(pop_max, -99)
You can also use the PostgreSQL instruction
NULLS FIRST or
NULLS LAST to define where you want the NULLs to be!
SELECT cartodb_id, column FROM table_name ORDER BY column DESC NULLS LAST