Re: Replace NULL values - Mailing list pgsql-general

From Stefan Schwarzer
Subject Re: Replace NULL values
Date
Msg-id 02457F1F-149A-421D-BF55-FF85113B18BD@grid.unep.ch
Whole thread Raw
In response to Re: Replace NULL values  (Martijn van Oosterhout <kleptog@svana.org>)
Responses Re: Replace NULL values  (Martijn van Oosterhout <kleptog@svana.org>)
Re: Replace NULL values  (Sim Zacks <sim@compulab.co.il>)
List pgsql-general
> On Thu, Sep 07, 2006 at 07:45:19AM +0200, Stefan Schwarzer wrote:
>> Hi there,
>>
>> is there a simple way to replace NULL values in multiple columns
>> within the SQL statement? I changed the underlaying country template
>> of your database; so now there are a couple of NULL values when I
>> join the stats-table with the country table. Unfortunately, my
>> queries have always multiple (year) columns, so I can't do a kind of
>> manual replace.
>>
>> I found that the COALESCE command does something like this, but I
>> couldn't figure out how this works.
>
> Yes, COALESCE replaces NULLs, however your examples have neither NULLs
> nor use COALESCE, so I don't understand what your question is.
>
> Please repost with an actual example of your problem.

As I said, I couldn't figure out how COALESCE would work on multiple
columns (without naming them explicitly).

So, say I have a table with columns for each year between 1970 and
2005. For specific countries the values might be NULL, depending if
the statistical table has been updated recently (then they will have
a value), or not (then they will be NULL). A sample query would thus
be something like:

     SELECT * FROM pop_density




pgsql-general by date:

Previous
From: Martijn van Oosterhout
Date:
Subject: Re: Replace NULL values
Next
From: Martijn van Oosterhout
Date:
Subject: Re: Replace NULL values