From: | Nilesh Govindarajan <lists(at)itech7(dot)com> |
---|---|
To: | Osvaldo Kussama <osvaldo(dot)kussama(at)gmail(dot)com> |
Cc: | pgsql-general General <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Replace null values |
Date: | 2010-03-23 04:45:07 |
Message-ID: | 4BA84753.5080100@itech7.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On 03/23/2010 09:47 AM, Osvaldo Kussama wrote:
> 2010/3/23 Nilesh Govindarajan<lists(at)itech7(dot)com>:
>> Hi,
>>
>> In my query, some rows have null values (length 0).
>
> NULL or a zero lenght string?
>
>
>>
>> I wish to replace them with some constant.
>>
>> I think I am wrong somewhere in this query using coalesce():
>>
>> select coalesce(u.name, 'anon'), nodecount from users u, ( select n.uid
>> userid, count(n.nid) nodecount from node n group by n.uid order by n.uid )
>> t1 where u.uid = t1.userid order by nodecount;
>>
>> The output is same as that of without coalesce.
>>
>
>
> bdteste=# SELECT coalesce(NULL, 'anon'), coalesce('', 'anon');
> coalesce | coalesce
> ----------+----------
> anon |
> (1 registro)
>
> Osvaldo
It is a zero length string. Somebody on the list suggested to use CASE.
It worked. Thanks anyways.
Got to learn about coalesce that it replaces null values and not zero
length strings.
How to convert zero length string to null ?
--
Nilesh Govindarajan
Site & Server Administrator
www.itech7.com
From | Date | Subject | |
---|---|---|---|
Next Message | A. Kretschmer | 2010-03-23 05:56:35 | Re: Create a function that updates the record with and timestamps |
Previous Message | Nilesh Govindarajan | 2010-03-23 04:39:16 | Re: Replace null values |