Re: Replace NULL values

From: Sim Zacks <sim(at)compulab(dot)co(dot)il>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Replace NULL values
Date: 2006-09-07 11:40:36
Message-ID: edot55$2vqo$1@news.hub.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Sim Zacks 2006-09-07 11:47:53 Re: Asynchronous trigger
Previous Message Stefan Schwarzer 2006-09-07 11:39:06 Re: Replace NULL values