coalesce for null AND empty strings

Поиск
Список
Период
Сортировка
От Ferdinand Gassauer
Тема coalesce for null AND empty strings
Дата
Msg-id 200703281450.59194.gassauer@kde.org
обсуждение исходный текст
Ответы Re: coalesce for null AND empty strings  (Richard Huxton <dev@archonet.com>)
Re: coalesce for null AND empty strings  (Alban Hertroys <alban@magproductions.nl>)
Re: coalesce for null AND empty strings  (Lew <lew@nospam.lewscanon.com>)
Список pgsql-general
Hi!

it would be great to have a coalesce2 function which treats empty strings as
null values.

as far as I have seen, there are a lot of comments and coding solutions about
this, but none is an "easy" one and all make the code a bit more complicated
and more difficult to maintain.

I have created this function.
It's similar to nullif, but takes only  ONE argument

create or replace function "empty2null"(text_i varchar)
returns varchar as $$
declare
text_p varchar;
begin
if text_i = ''
 then text_p := null;
 else text_p := text_i;
end if;
return text_p;
end;
$$ LANGUAGE plpgsql;


--
cu
Ferdinand

В списке pgsql-general по дате отправления:

Предыдущее
От: "Kev"
Дата:
Сообщение: Re: cutting out the middleperl
Следующее
От: "Dmitry Koterov"
Дата:
Сообщение: Re: How to speedup CHECKPOINTs?