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

From Peter Eisentraut
Subject Re: Needed function IF(expr, expr, expr)
Date
Msg-id Pine.LNX.4.44.0309061603250.1243-100000@peter.localdomain
Whole thread Raw
In response to Needed function IF(expr, expr, expr)  ("Marek Lewczuk" <newsy@lewczuk.com>)
Responses Re: Needed function IF(expr, expr, expr)
Re: Needed function IF(expr, expr, expr)
List pgsql-general
Marek Lewczuk writes:

> I'm moving out from MySQL to PostgreSQL and there are some function
> which are not supported in PG so I'm trying to write my own functions.
> Currently I have big problem with function IF(), below the description
> of this function from MySQL manual.

You cannot implement this kind of function, unless you want to create one
version for each data type combination.  But consider replacing the IF()
function with the standard CASE expression:

CASE WHEN expr1 THEN expr_if_true ELSE expr_if_false END

Also note that in PostgreSQL there is a boolean type, and 0 and 1 are not
valid boolean values.

--
Peter Eisentraut   peter_e@gmx.net


pgsql-general by date:

Previous
From: "Marek Lewczuk"
Date:
Subject: Needed function IF(expr, expr, expr)
Next
From: Bruno Wolff III
Date:
Subject: Re: Needed function IF(expr, expr, expr)