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: web-510100@davinci.ethosmedia.com (view raw or flat)
Thread:
Lists: pgsql-novice
Francisco,

> 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 Postgresql.org --> 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

-Josh

______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

Responses

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-2014 The PostgreSQL Global Development Group