Re: If function available? - Mailing list pgsql-novice

From Josh Berkus
Subject Re: If function available?
Date
Msg-id web-510100@davinci.ethosmedia.com
Whole thread Raw
In response to If function available?  (Francisco Reyes <lists@natserv.com>)
Responses Re: If function available?
List 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@agliodbs.com
   and data management solutions       (415) 565-7293
  for law firms, small businesses        fax 621-2533
    and non-profit organizations.      San Francisco

pgsql-novice by date:

Previous
From: "Josh Berkus"
Date:
Subject: Re: Trouble with MS Access-to-postgresql export
Next
From: James Olsen
Date:
Subject: Re: 7.1.3 compilation failure (libpq or aync?)