title: Redshift - Insert data into a temp table with a condition : column doc_id should be unique and not null
body: <p>I'm trying to create a temp table and insert data into it in Redshift.
  My goal is to create a single record for <strong>unique</strong> doc_id WHERE doc_id <strong>IS NOT NULL</strong>.</p>
  <p>Here's my code:</p>
  <pre><code>-- Creating temp table to load only rows with unique and not null doc_id
  DROP TABLE IF EXISTS TMP_table CASCADE;
  
  CREATE TEMP TABLE IF NOT EXISTS TMP_table
  (
      uuid varchar,
      id integer,
      doc_id integer,
      revenue double,
      doc_date varchar,
  );
  
  -- insert into the temp table and add the distinct and not null filter on the doc_id
  INSERT INTO TMP_table
  (
      uuid,
      id,
      doc_id,
      revenue,
      doc_date
  )
  SELECT
      uuid,
      id,
      select DISTINCT (table_x.doc_id) from schema.table_x where table_x.doc_id IS NOT NULL,
      revenue,
      doc_date
  FROM schema.table_x;
  </code></pre>
  <p>Upon running the above code I get a syntax error near the select subquery in the insert statement. And I can't seem to figure out what the error is.</p>
  <p>Any guidance please?</p>