Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is the CASE statement unnecessary? #21

Open
eliasmalik opened this issue Dec 15, 2017 · 0 comments
Open

Is the CASE statement unnecessary? #21

eliasmalik opened this issue Dec 15, 2017 · 0 comments

Comments

@eliasmalik
Copy link

In this query:

db.query('SELECT CASE WHEN EXISTS(SELECT gitterhandle FROM users WHERE gitterhandle = $1) THEN CAST (true AS BOOLEAN) ELSE CAST (false AS BOOLEAN) END', [gitterhandle]);

You're using a CASE statement to return a boolean, when your condition already returns a boolean. This is analogous to:

if (x == y) {
  return true;
} else {
  return false;
}

Simpler would be return x == y;. In the case of your query, you can get rid of the CASE statement and just use EXISTS directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant