title: How to get column dependencies in views in Redshift or Postgres?
body: <p>I've defined some views, built on other views/tables in Redshift, and would like to get info from the system tables regarding the dependencies at the column level.</p>
  
  <p>Say, for example, I have these definitions:</p>
  
  <pre><code>CREATE TABLE t1 AS (SELECT 2 as a, 4 as b, 99 as c );
  CREATE VIEW v1 AS (SELECT a, b FROM t1);
  CREATE VIEW v2 AS (SELECT a*b/2 as x FROM v1);
  </code></pre>
  
  <p>What I'd like to do is create some sort of query on the system or catalog tables that will return something like:</p>
  
  <pre><code>target_column |  target_table_or_view | source_column | source_table_or_view |
  ------------------------------------------------------------------------------
       x        |          v2           |        a      |           v1
       x        |          v2           |        b      |           v1
       a        |          v1           |        a      |           t1
       b        |          v1           |        b      |           t1
  </code></pre>
  
  <p>I've tried the solution given here: <a href="https://stackoverflow.com/questions/43876922/how-to-create-a-dependency-list-for-an-object-in-redshift?rq=1">How to create a dependency list for an object in Redshift?</a>. However, this query doesn't produce the "target column" column I'm looking for and I don't know how to adjust it.</p>
  
  <p>Is this possible? Ideally I'd like to do this in Redshift, but if needed I can use a newer version of Postgres.</p>