0
Select
   id,
   username,
   is_null(email) AS has_email,
FROM
  users
;

I want to write the above query, but instead of returning the email, I only want it to return whether there is an email. Is there a way to do that?

2
  • Why do you consider an email that is null to be a sign that there is an email? Don't you rather want to test for "not null"? Commented Nov 23, 2014 at 20:06
  • This is all documented in the manual btw: postgresql.org/docs/current/static/functions-comparison.html Commented Nov 23, 2014 at 20:08

1 Answer 1

2

Try this

Select
   id,
   username,
   email IS NOT NULL AS has_email
FROM
   users
;

Edit: changed IS NULL to IS NOT NULL

Sign up to request clarification or add additional context in comments.

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.