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

Re: Using CASE with a boolean value

From: "Joel Burton" <joel(at)joelburton(dot)com>
To: <tansley(at)law(dot)du(dot)edu>,"Postgresql Novice List" <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Using CASE with a boolean value
Date: 2002-05-24 15:59:37
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-novice
> I'm trying to use a case statement with a boolean value.  i.e.
> if the value =
> false then output 'NO', if value = true then output 'YES'.  This
> is what I
> came up with
> CASE booking.quiz
> 	WHEN booking.quiz=false THEN 'No'
> 	WHEN booking.quiz=true THEN 'Yes'
> 	ELSE 'No'
> But, it isn't working.  Everything compiles and the rows returned
> are correct
> but it still returns 'true' or 'false' rather than 'YES' or 'NO'.
>  I've also
> tried this
> CASE booking.quiz
> 	WHEN booking.quiz='f' THEN 'No'
> 	WHEN booking.quiz='t' THEN 'Yes'
> 	ELSE 'No'
> and this
> CASE booking.quiz
> 	WHEN booking.quiz='false' THEN 'No'
> 	WHEN booking.quiz='true' THEN 'Yes'
> 	ELSE 'No'
> Anybody got any ideas?  Should the value be cast into a string?

create table bools (b bool);
insert into bools values (true);
insert into bools values (false);
select case b when true then 'yes' when false then 'no' else 'unknown' end
from bools;

(2 rows)

Seems to work just fine. Can you post a full example of this not working,

- J.

Joel BURTON | joel(at)joelburton(dot)com | | aim: wjoelburton
Knowledge Management & Technology Consultant

In response to

pgsql-novice by date

Next:From: Tom AnsleyDate: 2002-05-24 16:15:55
Subject: Re: Using CASE with a boolean value
Previous:From: Tom AnsleyDate: 2002-05-24 15:55:04
Subject: Using CASE with a boolean value

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