title: PostgreSQL: Select from table only if table exists
body: <p>I am an SQL noob, and I have been trying to select data only if a table exists, and nothing if it doesn't. I've looked at various solutions, and this is the best I've been able to come up with:</p>
  <pre><code>DO $$                  
      BEGIN 
          IF EXISTS
              ( SELECT 1
                FROM   information_schema.tables 
                WHERE  table_schema = 'public'
                AND    table_name = &quot;Test_Table&quot;
              )
          THEN
              SELECT
                test_col
              FROM &quot;Test_Table&quot;
              ORDER BY time ASC
          END IF ;
      END
  $$ ;
  </code></pre>
  <p>but this gives:</p>
  <pre><code>ERROR:  syntax error at or near &quot;END&quot;
  LINE 14:         END IF ;
  </code></pre>
  <p>Note that the table name may contain uppercase characters, so I believe the double quotes are necessary.</p>
  <p>Any ideas? Maybe trying to catch an exception would be a better approach?</p>
  <p>Thanks!</p>