title: How to SELECT without error if table does not exist
body: <p>I'd like to run a <code>SELECT</code> from a given table, which should not fail if the table doesn't exist. Let's say, for simplicity, that the table contains only one column and one row and I'm after that scalar. If the table doesn't exist I want to get back <code>0</code>.</p>
  
  <p>I know I could do something like:</p>
  
  <pre><code>query("select count(1) from information_schema.tables where table_name = 'versions'")
  if result &gt; 0
    return query("select version from versions limit 1")
  else
    return 0
  </code></pre>
  
  <p>Or I could do the equivalent using a stored procedure / plpgsql function.</p>
  
  <p>But is there a way to do the same in a single ad-hoc query?</p>
  
  <p>(I'm doing two queries. I don't have a good reason to change it. I'm just curious whether/how it's possible to do.)</p>