Re: Syntax for "IF" clause in SELECT - Mailing list pgsql-sql

From Ken Hill
Subject Re: Syntax for "IF" clause in SELECT
Date
Msg-id 1139450771.15713.5.camel@localhost.localdomain
Whole thread Raw
In response to Re: Syntax for "IF" clause in SELECT  (Bricklen Anderson <banderson@presinet.com>)
Responses Re: Syntax for "IF" clause in SELECT  (Andrew Sullivan <ajs@crankycanuck.ca>)
List pgsql-sql
This has been something I've been trying do so that I can do some column comparisons as part of "data-cleaning" work.
I'lllet you know if this helps me accomplish my task!<br /><br /> On Wed, 2006-02-08 at 15:20 -0800, Bricklen Anderson
wrote:<blockquote type="CITE"><pre>
 
<font color="#000000"><a href="mailto:pgsql@yukonho.de">pgsql@yukonho.de</a> wrote:</font>
<font color="#000000">> Greetings,</font>
<font color="#000000">> </font>
<font color="#000000">> the following is an MySQL statement that I would like to</font>
<font color="#000000">> translate to PostgreSQL:</font>
<font color="#000000">> </font>
<font color="#000000">> Could someone point me to a documentation of a coresponding</font>
<font color="#000000">> Systax for an "IF" clause in the a SELECT, </font>
<font color="#000000">> or is the some other way to do this....</font>
<font color="#000000">> </font>
<font color="#000000">> select</font>
<font color="#000000">>  if(spektrum is null,' ','J'),</font>
<font color="#000000">>  if(s19 is null,' ','J'),</font>
<font color="#000000">>  if(OhneGrenze is null,' ','J'),</font>
<font color="#000000">>  from namen;</font>
<font color="#000000">> </font>
<font color="#000000">> </font>
<font color="#000000">> Do I need to create my own function to allow this behaviour!</font>
<font color="#000000">> </font>
<font color="#000000">> </font>
<font color="#000000">> my best regards,</font>
<font color="#000000">> </font>
<font color="#000000">> Stefan</font>

<font color="#000000">use CASE</font>

<font color="#000000">Since I'm not a user of MySQL, and if I'm reading your query correctly:</font>
<font color="#000000">try</font>
<font color="#000000">select (CASE when spektrum is null then 'J' else spektrum end),</font>
<font color="#000000">...</font>

<font color="#000000">or if you are just trying to replace nulls, then try COALESCE</font>

<font color="#000000">---------------------------(end of broadcast)---------------------------</font>
<font color="#000000">TIP 1: if posting/reading through Usenet, please send an appropriate</font>
<font color="#000000">       subscribe-nomail command to <a
href="mailto:majordomo@postgresql.org">majordomo@postgresql.org</a>so that your</font>
 
<font color="#000000">       message can get through to the mailing list cleanly</font>
</pre></blockquote>

pgsql-sql by date:

Previous
From: george young
Date:
Subject: unique constraint instead of primary key? what disadvantage(ODBC usage)?
Next
From: Ken Hill
Date:
Subject: Re: unique constraint instead of primary key? what