Re: [SQL] CASE WHEN / 6.4.2? + no doc in installed documentation

From: Fomichev Michael <fomichev(at)null(dot)ru>
To: Emils Klotins <emils(at)mail(dot)usis(dot)bkc(dot)lv>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: [SQL] CASE WHEN / 6.4.2? + no doc in installed documentation
Date: 1999-05-26 20:57:01
Message-ID: Pine.LNX.4.04.9905270956000.606-100000@ns.region.utsr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Wed, 26 May 1999, Emils Klotins wrote:
>
> I have a SELECT that needs to return a value, if another value is not null, otherwise it should
> return a string 'N/A':
> A simpliefied version of SELECT is this:
>
> SELECT category, CASE (WHEN category IS NULL THEN 'N/A' ELSE name) AS name FROM
> mytable;
>
> I get 'parse error near category'.
>

Try this:

SELECT category, name FROM mytable WHERE category IS NOT NULL
UNION ALL
SELECT category, 'N/A' FROM mytable WHERE category IS NULL;

field `name' must have char type.

Browse pgsql-sql by date

  From Date Subject
Next Message Robert Chalmers 1999-05-27 01:20:36 pgsql and shopping carts - is there any development code out there?
Previous Message Steven M. Wheeler 1999-05-26 18:07:13 Re: [SQL] Re: pgsql-sql-digest V1 #225