- Explore
- Collaborate
- Visualize
- Connect
- Pricing
How to Use Coalesce in PostgreSQL
Say you're looking at a PostgreSQL integer column where some rows are null:
select
day,
tickets
from stats;
day | tickets
------------+-------
2018-01-01 | 1
2018-01-02 | null
2018-01-03 | 3
Instead of having that null, you might want that row to be 0
. To do that, use the coalesce
function, which returns the first non-null argument it's passed:
select
day,
coalesce(tickets, 0)
from stats;
day | tickets
------------+-------
2018-01-01 | 1
2018-01-02 | 0
2018-01-03 | 3
From PostgreSQL query to chart to Slack in seconds
Get to answers faster, together, with PopSQL and PostgreSQL
From PostgreSQL query to chart to Slack in seconds
Get to answers faster, together, with PopSQL and PostgreSQL