0

If I have a table like this:

Screenshot

How can I turn all NULL values to 0?
Using:

SELECT coalesce(area::text, 0) as area,
       coalesce(duration::text, 0) as duration

But it keeps saying:

COALESCE types text and integer cannot be matched.

Erwin Brandstetter
  • 605,456
  • 145
  • 1,078
  • 1,228
  • 2
    `SELECT coalesce(area, '0') as area, coalesce(duration, '0') as duration,` – Adrian Klaver Jul 14 '22 at 22:08
  • Cast that 0 to text (Or just quote it) or duration to integer. – bitifet Jul 14 '22 at 22:09
  • 3
    The true solution is to repair your broken table design and use a [numeric type](https://www.postgresql.org/docs/current/datatype-numeric.html) for your numeric `data` in area and `duration`. Then your original query works, too. But read up on [data type casts](https://stackoverflow.com/a/13676871/939860) as well. – Erwin Brandstetter Jul 14 '22 at 23:52

0 Answers0