Skip site navigation (1) Skip section navigation (2)

Re: [pgsql-ru-general] Re: [pgsql-ru-general] Re[2]: [pgsql-ru-general] настройк

From: "Andrey N(dot) Oktyabrski" <ano(at)antora(dot)ru>
To: pgsql-ru-general(at)postgresql(dot)org
Subject: Re: [pgsql-ru-general] Re: [pgsql-ru-general] Re[2]: [pgsql-ru-general] настройк
Date: 2005-12-06 09:45:30
Message-ID: 43955DBA.2060600@antora.ru (view raw or flat)
Thread:
Lists: pgsql-ru-general
Teodor Sigaev wrote:
> select 'test' || coalesce(NULL, '') || '' as ret;

>>>> Можно настроить PostgreSQL, чтобы запрос
>>>> select 'test' || NULL || '' as ret;
>>>> возвращал не пустую строку, а то, что есть ?
>>
>> Задача совершенно простая, в таблице есть поля "фамилия", "имя",
>> "отчество".
>> Я хочу чтобы запрос возвратил мне одно поле "Фамилия И.О.", а
>> отчество может быть NULL, и соответственно возвращается пустая строка.
>>
>> Стандартной функции на проверку строки на NULL, и замену на "" не
>> нашел. Написать свою ?
file:///usr/local/share/doc/postgresql/html/functions-conditional.html#AEN12614
9.13.2. COALESCE

COALESCE(value [, ...])

The COALESCE function returns the first of its arguments that is not
null. Null is returned only if all arguments are null. This is often
useful to substitute a default value for null values when data is
retrieved for display, for example:

SELECT COALESCE(description, short_description, '(none)') ...

Like a CASE expression, COALESCE will not evaluate arguments that are
not needed to determine the result; that is, arguments to the right of
the first non-null argument are not evaluated.

In response to

pgsql-ru-general by date

Next:From: GenixDate: 2005-12-06 13:24:49
Subject: insert в varchar
Previous:From: Teodor SigaevDate: 2005-12-06 09:15:25
Subject: Re: [pgsql-ru-general] Re[2]: [pgsql-ru-general] настройк

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group