Re: What does Postgresql do when using CASE WHEN without ELSE?

Поиск
Список
Период
Сортировка
От Seref Arikan
Тема Re: What does Postgresql do when using CASE WHEN without ELSE?
Дата
Msg-id CA+4ThdrGP7a2zpxjABcdNR-JvEhsc2aWNbSJm8teez3sR=9zjQ@mail.gmail.com
обсуждение исходный текст
Ответ на What does Postgresql do when using CASE WHEN without ELSE?  (Seref Arikan <serefarikan@kurumsalteknoloji.com>)
Список pgsql-general
Apologies, I found the answer in the documentation:
http://www.postgresql.org/docs/9.0/static/functions-conditional.html says:
"If the ELSE clause is omitted and no condition is true, the result is
null."

Best regards
Seref



On Tue, Feb 12, 2013 at 10:39 AM, Seref Arikan <
serefarikan@kurumsalteknoloji.com> wrote:

> Greetings,
> I want to use CASE WHEN to make sure that I don't try to call a function
> on a row that does not exist. This is used within a WHERE statement as
> follows (without the function call I've mentioned);
>
> WHERE
>       CASE WHEN EXISTS(SELECT ATRNODE.featuremappingid from ELEMENT1,
> ATRNODE where ELEMENT1.pathstring || '/' || 'name/value' =3D
> ATRNODE.pathstring)
>       THEN
>       (   ELEMENT1.pathstring || '/' || 'name/value' =3D ATRNODE.pathstri=
ng
>           and
>           ATRNODE.valstring =3D 'M=E5ltillst=E5nd' --this will be where t=
he
> function is going to be used
>       )
>       ELSE
>        ELEMENT1.id =3D -1291927189371983619872981729
>       END
>
> The overall mechanism lets me apply a constraint so that if a row does no=
t
> exist, the query returns no results, without attempting to process
> ATRNODE.valstring value (which represents more complicated info that will
> exist in the row in other cases)
> The thing is, when I omit the ELSE, the query still returns no results if
> the row does not exist. It is as if an ELSE statement is added with an
> impossible constraint, just like the one I'm explicitly providing.
>  I'm keeping the ELSE so that I explicitly introduce a where statement
> that will not correspond to any rows, but what is happening when I omit
> ELSE, so that the query still functions as it should?
>
> Best regards
> Seref
>
>

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

Предыдущее
От: Chris Travers
Дата:
Сообщение: Re: How to store version number of database layout
Следующее
От: Modulok
Дата:
Сообщение: Re: Can you create aliases in the psql shell?