From: | Tino Wildenhain <tino(at)wildenhain(dot)de> |
---|---|
To: | Sergey Karin <sergey(dot)karin(at)gmail(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: NULL values and string |
Date: | 2006-02-02 10:59:04 |
Message-ID: | 43E1E5F8.8050604@wildenhain.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Sergey Karin schrieb:
> Hi, List!
>
> I'm using PG8.1.
>
> Are there any abilities to represent NULL values as string?
>
> I'm doing something like this:
>
> create function func(int4) returns varchar as'
> declare
> num_value alias for $1;
> string_value varchar;
> begin
>
> string_value := \'input value = \' || num_value;
> return string_value;
>
> end
> 'language 'plpgsql';
>
>
> If I einvoke my function with NULL argument, it return NULL. But I want
> 'input value = NULL'.
> Of course, I can check input value like this:
>
> if(num_value isnull) then
> string_value := \'input value = NULL\';
> else
> string_value := \'input_value = \' || num_value;
> end if;
>
You can use COALESCE()
create function func(int4) returns text as $$
declare
num_value alias for $1;
begin
return 'input value = ' || COALESCE(num_value,'NULL');
end
$$ language 'plpgsql';
(Id rather use more descriptive name for your function)
Regards
Tino
From | Date | Subject | |
---|---|---|---|
Next Message | Richard Huxton | 2006-02-02 11:02:21 | Re: NULL values and string |
Previous Message | Sergey Karin | 2006-02-02 10:44:35 | NULL values and string |