1

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

2
  • That sort of formatting really belongs in your application (IMO), a simple dictionary should do the trick in Python or possible a dictionary combined with your localized string handling system if you care about people that don't read English. Commented Dec 19, 2011 at 22:38
  • @A.H oh haha actually no, I just wanted to show you guys the data types Commented Dec 19, 2011 at 22:45

2 Answers 2

7
SELECT name::text, id::int, 
CASE WHEN pass = true THEN 'passed' ELSE 'failed' END AS pass 
FROM mytable;
Sign up to request clarification or add additional context in comments.

Comments

4

You can use this one:

select case pass when true then 'passed' when false then 'failed' else null end pass from...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.