title: How to use an array as a variable in Postgres?
body: <p>I have this .sql script:</p>
  
  <pre><code>DO $$
    DECLARE 
      user_list integer[] = (select user_id from user where state = 'ACTIVE');
  BEGIN
      CREATE CREATE MATERIALIZED VIEW accounts_with_active_users AS
      select * from accounts where user_account IN (user_list);
      ...
  
      CREATE CREATE MATERIALIZED VIEW accounts_without_active_users AS
      select * from accounts where user_account NOT IN (user_list);
      ...
  END $$;
  </code></pre>
  
  <p>However I always have this error:</p>
  
  <pre><code>ERROR: cannot cast type integer to integer[]
  </code></pre>
  
  <p>Also I have tried with the word <code>array</code> before with the same result:</p>
  
  <pre><code>user_list integer[] = array(...)
  </code></pre>