What does Postgresql do when using CASE WHEN without ELSE?

From: Seref Arikan <serefarikan(at)kurumsalteknoloji(dot)com>
To: PG-General Mailing List <pgsql-general(at)postgresql(dot)org>
Subject: What does Postgresql do when using CASE WHEN without ELSE?
Date: 2013-02-12 10:39:16
Message-ID: CA+4ThdpQfxDVdS_FeaCrkA2D6_Q2UKAC0SdS9x9aoo7SiMrujQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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' =
ATRNODE.pathstring)
THEN
( ELEMENT1.pathstring || '/' || 'name/value' = ATRNODE.pathstring
and
ATRNODE.valstring = 'Måltillstånd' --this will be where the
function is going to be used
)
ELSE
ELEMENT1.id = -1291927189371983619872981729
END

The overall mechanism lets me apply a constraint so that if a row does not
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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message John R Pierce 2013-02-12 10:40:00 Re: How to store version number of database layout
Previous Message Philipp Kraus 2013-02-12 10:19:29 libpq compatibility