Skip site navigation (1) Skip section navigation (2)

Re: If function available?

From: "Josh Berkus" <josh(at)agliodbs(dot)com>
To: Francisco Reyes <lists(at)natserv(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: If function available?
Date: 2001-11-20 16:35:42
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-novice

> I tried it from the psql prompt and didn't work. Is there an IF or
> IIF function that can be used on a select query?

You want CASE, as in:

CASE WHEN field1 = 1 THEN NULL ELSE field1 END

See --> Documentation --> SQL Commands --> SELECT for
more information, or consult your favorite SQL92 manual.

There are also several special functions for dealing with NULL output,
such as:

COALESCE(x,y,z) : returns first non-null value
NULLIF(x, y) : returns NULL if x = y


______AGLIO DATABASE SOLUTIONS___________________________
                                       Josh Berkus
  Complete information technology      josh(at)agliodbs(dot)com
   and data management solutions       (415) 565-7293
  for law firms, small businesses        fax 621-2533
    and non-profit organizations.      San Francisco

In response to


pgsql-novice by date

Next:From: Josh BerkusDate: 2001-11-20 16:41:40
Subject: Re: Emergency backup question.
Previous:From: Tom LaneDate: 2001-11-20 15:21:04
Subject: Re: Emergency backup question.

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group