How to work with NULL values in CARTO datasets
Learn how to select, populate or delete NULL values in CARTO datasets.
- To replace all
NULLvalues in a column you can use theCOALESCEPostgreSQL function. This replacesnullwith 0, becausecolumnis number-type:
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 withNULLones:
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