Re: Syntax for "IF" clause in SELECT

From: Bricklen Anderson <banderson(at)presinet(dot)com>
To: pgsql(at)yukonho(dot)de
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Syntax for "IF" clause in SELECT
Date: 2006-02-08 23:20:45
Message-ID: 43EA7CCD.3050905@presinet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

pgsql(at)yukonho(dot)de wrote:
> Greetings,
>
> the following is an MySQL statement that I would like to
> translate to PostgreSQL:
>
> Could someone point me to a documentation of a coresponding
> Systax for an "IF" clause in the a SELECT,
> or is the some other way to do this....
>
> select
> if(spektrum is null,' ','J'),
> if(s19 is null,' ','J'),
> if(OhneGrenze is null,' ','J'),
> from namen;
>
>
> Do I need to create my own function to allow this behaviour!
>
>
> my best regards,
>
> Stefan

use CASE

Since I'm not a user of MySQL, and if I'm reading your query correctly:
try
select (CASE when spektrum is null then 'J' else spektrum end),
...

or if you are just trying to replace nulls, then try COALESCE

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Ken Hill 2006-02-09 01:53:59 Column Index vs Record Insert Trade-off?
Previous Message pgsql 2006-02-08 23:12:52 Syntax for "IF" clause in SELECT