title: PostgreSQL: CASE: SELECT FROM two different tables
body: <ol>
  <li><p>Is it possible to do something like the following with SQL, not PL/pgSQL (note if it's only possible with PL/pgSQL, then how)?</p>
  
  <pre><code>IF password = 'swordfish' THEN
      SELECT a, b, c FROM users;
  ELSE
      SELECT -1; -- unauthorized error code
  END IF;
  </code></pre></li>
  <li><p>Ideally, could I wrap the above in a function with <code>TRUE</code> being an argument?</p></li>
  <li><p>Rather, is it possible to set the <a href="http://www.postgresql.org/docs/9.3/static/rules-status.html" rel="nofollow">command status string</a> to -1?</p></li>
  </ol>
  
  <p>I'm asking this because I want the query to return an error code, like -1, if someone tries to get a list of all the users with the wrong password. This is for a web app with user accounts that each have a password. So, this is not something I want to manage with database roles/permissions.</p>