Re: Replace NULL values

From: Stefan Schwarzer <stefan(dot)schwarzer(at)grid(dot)unep(dot)ch>
To: Martijn van Oosterhout <kleptog(at)svana(dot)org>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Replace NULL values
Date: 2006-09-07 09:54:43
Message-ID: 02457F1F-149A-421D-BF55-FF85113B18BD@grid.unep.ch
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Martijn van Oosterhout 2006-09-07 10:11:19 Re: Replace NULL values
Previous Message Martijn van Oosterhout 2006-09-07 09:47:14 Re: Replace NULL values