Reputation: 2994
Say I have this query:
SELECT name::text, id::int, pass:bool FROM mytable;
which gives me this view table:
name id pass
------------------
A 123 t
B 234 t
C 345 f
How do I tell postgres to give me this instead
name id pass
--------------------
A 123 passed
B 234 passed
C 345 failed
I tried the CASE WHEN condition THEN result;
but that just gives me another column 'case'.
(if there's no easy way for postgres, is there any in psycopg2 ? because I mainly use it to get the data I want)
Thanks in advance
Upvotes: 1
Views: 540
Reputation: 66273
You can use this one:
select case pass when true then 'passed' when false then 'failed' else null end pass from...
Upvotes: 4
Reputation: 72626
SELECT name::text, id::int,
CASE WHEN pass = true THEN 'passed' ELSE 'failed' END AS pass
FROM mytable;
Upvotes: 7