Re: Needed function IF(expr, expr, expr)

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Needed function IF(expr, expr, expr)
Дата
Msg-id 1178.1062897207@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: Needed function IF(expr, expr, expr)  (Greg Stark <gsstark@mit.edu>)
Список pgsql-general
Greg Stark <gsstark@mit.edu> writes:
> For 7.4 you'll be able to define it something like this:
> (I'm not sure why "anyelement" works but "any" doesn't work.)

Because "any" doesn't imply anything about relationships between
datatypes of arguments and results.  You need "anyelement" to inform
the parser that the result type is the same as the second and third
argument types.  "any" is just a wildcard.

> slo=> create or replace function iff(boolean,"anyelement","anyelement") returns "anyelement" language sql strict
immutableas 'select case when $1 then $2 else $3 end' ; 

You don't want this to be STRICT: "if(true,33,null)" should yield 33 not
null, no?

            regards, tom lane

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

Предыдущее
От: elein
Дата:
Сообщение: Re: Trunc in Postgres
Следующее
От: Alex
Дата:
Сообщение: Reasonable Configuration