samol
samol

Reputation: 20570

Postgres function to check if something is null

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?

Upvotes: 0

Views: 269

Answers (1)

Try this

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

Edit: changed IS NULL to IS NOT NULL

Upvotes: 2

Related Questions