This content applies to a previous version of CARTO
In October 2021 we released a new version of our platform. You can find the latest documentation at docs.carto.com
Back to Help Center
How to Work with NULL Values in CARTO Datasets
Learn how to select, populate or delete NULL values in CARTO datasets.
Replacing NULL values
To replace all NULL values in a column, use the COALESCE PostgreSQL function. This example replaces null with 0 for number-type columns:
UPDATE table_name SET column = COALESCE(column, 0)
If your column is string-type, enclose the second COALESCE argument in single quotes.
Converting values to NULL
You can use NULLIF to replace non-null values with NULL ones:
UPDATE populated_places SET pop_max = NULLIF(pop_max, -99)
Ordering NULL values
Use the PostgreSQL instructions NULLS FIRST or NULLS LAST to define where NULL values appear in results:
SELECT
cartodb_id,
column
FROM
table_name
ORDER BY
column DESC NULLS LAST
