title: Getting table information for Redshift `stl_load_errors` errors
body: <p>I am using Redshift COPY command to load data into Redshift table from S3. When something goes wrong, I typically get an error <code>ERROR:  Load into table 'example' failed.  Check 'stl_load_errors' system table for details</code>. I can always lookup <code>stl_load_errors</code> manually to get details. Now, I am trying to figure out how I can do that automatically. </p>
  
  <p>From <a href="http://docs.aws.amazon.com/redshift/latest/dg/r_STL_LOAD_ERRORS.html" rel="nofollow">documentation</a> it looks like the following query should give me all the details I need:</p>
  
  <pre><code>SELECT *
  FROM stl_load_errors errors
  INNER JOIN svv_table_info info
    ON errors.tbl = info.table_id
      AND info.schema = '&lt;schema-name&gt;'
      AND info.table = '&lt;table-name&gt;'
  </code></pre>
  
  <p>However it always returns nothing. I also tried using <code>stv_tbl_perm</code> instead of <code>svv_table_info</code>, and still nothing. </p>
  
  <p>After some troubleshooting, I see two things I don't understand:</p>
  
  <ol>
  <li>I see multiple different IDs in <code>stv_tbl_perm</code> and <code>svv_table_info</code> for the same exact table. Why is that?</li>
  <li>I see <code>tbl</code> filed on <code>stl_load_errors</code> referencing ids that do not exist in <code>stv_tbl_perm</code> or <code>svv_table_info</code>. Again why?</li>
  </ol>
  
  <p>Feels like I don't understanding something in structure of these tables, but it completely escapes me what. </p>