pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Syntax for "IF" clause in SELECT
4+ messages / 4 participants
[nested] [flat]

* Syntax for "IF" clause in SELECT
@ 2006-02-08 23:12  pgsql@yukonho.de
  0 siblings, 1 reply; 4+ messages in thread

From: pgsql@yukonho.de @ 2006-02-08 23:12 UTC (permalink / raw)
  To: pgsql-sql

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
-- 
email: stefan@yukonho.de
tel  : +49 (0)6232-497631
http://www.yukonho.de



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Syntax for "IF" clause in SELECT
@ 2006-02-08 23:20  Bricklen Anderson <banderson@presinet.com>
  parent: pgsql@yukonho.de
  0 siblings, 1 reply; 4+ messages in thread

From: Bricklen Anderson @ 2006-02-08 23:20 UTC (permalink / raw)
  To: pgsql@yukonho.de; +Cc: pgsql-sql

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



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Syntax for "IF" clause in SELECT
@ 2006-02-09 02:06  Ken Hill <ken@scottshill.com>
  parent: Bricklen Anderson <banderson@presinet.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Ken Hill @ 2006-02-09 02:06 UTC (permalink / raw)
  To: Bricklen Anderson <banderson@presinet.com>; +Cc: pgsql@yukonho.de; 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'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

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Syntax for "IF" clause in SELECT
@ 2006-02-09 13:32  Andrew Sullivan <ajs@crankycanuck.ca>
  parent: Ken Hill <ken@scottshill.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Andrew Sullivan @ 2006-02-09 13:32 UTC (permalink / raw)
  To: pgsql-sql

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



^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2006-02-09 13:32 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-02-08 23:12 Syntax for "IF" clause in SELECT pgsql@yukonho.de
2006-02-08 23:20 ` Bricklen Anderson <banderson@presinet.com>
2006-02-09 02:06   ` Ken Hill <ken@scottshill.com>
2006-02-09 13:32     ` Andrew Sullivan <ajs@crankycanuck.ca>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox