Re: Needed function IF(expr, expr, expr) - Mailing list pgsql-general

From Tom Lane
Subject Re: Needed function IF(expr, expr, expr)
Date
Msg-id 1178.1062897207@sss.pgh.pa.us
Whole thread Raw
In response to Re: Needed function IF(expr, expr, expr)  (Greg Stark <gsstark@mit.edu>)
List 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 by date:

Previous
From: elein
Date:
Subject: Re: Trunc in Postgres
Next
From: Alex
Date:
Subject: Reasonable Configuration