X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 667A69DC990 for ; Thu, 9 Feb 2006 09:32:45 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 41284-06 for ; Thu, 9 Feb 2006 09:32:48 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from r1.mycybernet.net (r1.mycybernet.net [209.5.206.8]) by postgresql.org (Postfix) with ESMTP id EE8FC9DC883 for ; Thu, 9 Feb 2006 09:32:42 -0400 (AST) Received: from 227-54-222-209.mycybernet.net ([209.222.54.227]:58025 helo=phlogiston.dydns.org) by r1.mycybernet.net with esmtp (Exim 4.50 (FreeBSD)) id 1F7Bud-0001Hv-G2 for pgsql-sql@postgresql.org; Thu, 09 Feb 2006 08:32:43 -0500 Received: by phlogiston.dydns.org (Postfix, from userid 1000) id 7E46C4046; Thu, 9 Feb 2006 08:32:38 -0500 (EST) Date: Thu, 9 Feb 2006 08:32:38 -0500 From: Andrew Sullivan To: pgsql-sql@postgresql.org Subject: Re: Syntax for "IF" clause in SELECT Message-ID: <20060209133238.GA21305@phlogiston.dyndns.org> References: <200602090012.52747.pgsql@yukonho.de> <43EA7CCD.3050905@presinet.com> <1139450771.15713.5.camel@localhost.localdomain> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1139450771.15713.5.camel@localhost.localdomain> User-Agent: Mutt/1.5.9i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.098 required=5 tests=[AWL=0.098] X-Spam-Score: 0.098 X-Spam-Level: X-Archive-Number: 200602/100 X-Sequence-Number: 24110 What you want is the SQL-standard CASE statement. A On Wed, Feb 08, 2006 at 06:06:10PM -0800, Ken Hill wrote: > This has been something I've been trying do so that I can do some column > comparisons as part of "data-cleaning" work. I'll let you know if this > helps me accomplish my task! > > On Wed, 2006-02-08 at 15:20 -0800, Bricklen Anderson wrote: > > > pgsql@yukonho.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 > > > > ---------------------------(end of broadcast)--------------------------- > > TIP 1: if posting/reading through Usenet, please send an appropriate > > subscribe-nomail command to majordomo@postgresql.org so that your > > message can get through to the mailing list cleanly -- Andrew Sullivan | ajs@crankycanuck.ca It is above all style through which power defers to reason. --J. Robert Oppenheimer