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

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Greg Stark <gsstark(at)mit(dot)edu>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Needed function IF(expr, expr, expr)
Date: 2003-09-07 01:13:27
Message-ID: 1178.1062897207@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

Greg Stark <gsstark(at)mit(dot)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 immutable as '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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Alex 2003-09-07 01:42:57 Reasonable Configuration
Previous Message Franco Bruno Borghesi 2003-09-07 00:07:38 SRF question

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2003-09-07 01:19:27 Re: sequences and pg_type
Previous Message pw 2003-09-06 22:56:19 sequences and pg_type