Re: case when evaluating else condition anyway?

Поиск
Список
Период
Сортировка
От Ivan Sergio Borgonovo
Тема Re: case when evaluating else condition anyway?
Дата
Msg-id 20081126161740.749580d4@dawn.webthatworks.it
обсуждение исходный текст
Ответ на Re: case when evaluating else condition anyway?  (Sam Mason <sam@samason.me.uk>)
Ответы Re: case when evaluating else condition anyway?  (Sam Mason <sam@samason.me.uk>)
Re: case when evaluating else condition anyway?  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-general
On Wed, 26 Nov 2008 14:18:44 +0000
Sam Mason <sam@samason.me.uk> wrote:

> On Wed, Nov 26, 2008 at 02:53:07PM +0100, Ivan Sergio Borgonovo
> wrote:
> > case when ''=extinput then null else extinput::timestamp end
>
> I'd tend to use nullif(extinput,'')::timestamp for this sort of

Thanks it was on the top of my fingers... BTW it was a substituted
literal ala printf before anything was piped to postgresql, so
actually postgresql would receive something as the examples below.

Still why does the else condition get evaluated anyway when at least
one of the "when" condition is true?

> thing. It's not going to do anything much different from what
> you're doing, but may end up evaluating "extinput" less which may
> be a good thing.
>
> > Is there any cleaner functional way that doesn't involve prepared
> > statement etc... since the whole exercise is caused by an
> > null-impaired DB API (aka MySQLish).
>
> As Tom said, maybe if you could send a larger example it would
> help.

as a more self contained example:

select case when ''='' then null else ''::timestamp end;

vs.

select nullif('','')::timestamp;

thanks

--
Ivan Sergio Borgonovo
http://www.webthatworks.it


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

Предыдущее
От: "Ronald Vyhmeister"
Дата:
Сообщение: Re: Problem with langage encoding
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Problem with langage encoding