Re: Replace NULL values - Mailing list pgsql-general

From Sim Zacks
Subject Re: Replace NULL values
Date
Msg-id edot55$2vqo$1@news.hub.org
Whole thread Raw
In response to Re: Replace NULL values  (Stefan Schwarzer <stefan.schwarzer@grid.unep.ch>)
Responses Re: Replace NULL values  (Stefan Schwarzer <stefan.schwarzer@grid.unep.ch>)
List pgsql-general
Aside from your database structure being problematic, what are you
trying to accomplish?
In other words, what do you want to replace the nulls with and in what
circumstance?
I imagine your table looks like this
ID,country,1950,1951,1952,1953,....
1   usa    50   null  70   10
2  canada  10   45   null   4

Please mention what you would like to do with this?


Stefan Schwarzer wrote:
>> 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
>
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 9: In versions below 8.0, the planner will ignore your desire to
>       choose an index scan if your joining column's datatypes do not
>       match
>

pgsql-general by date:

Previous
From: Martijn van Oosterhout
Date:
Subject: Re: Replace NULL values
Next
From: Sim Zacks
Date:
Subject: Re: Asynchronous trigger