title: Change owner to all tables with PostgreSQL function
body: <p>I want change owner for all tables in specific table_catalog with function:</p>
  <pre><code>CREATE OR REPLACE function change_owner_table_catalog(catalog_arg varchar, owner_arg varchar)
      RETURNS void AS $$
      DECLARE
      table_name_value varchar;
      sequence_name_value varchar;
      BEGIN
          for table_name_value in (SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' AND table_catalog = catalog_arg) loop
              ALTER TABLE table_name_value OWNER TO owner_arg;
          end loop;
      END;
      $$ language plpgsql;
  </code></pre>
  <p>I execute it:</p>
  <pre><code>select change_owner_table_catalog('cinema', 'cinema_user')
  </code></pre>
  <p>And have the next error:</p>
  <blockquote>
  <p>ERROR:  relation &quot;table_name_value&quot; does not exist
  CONTEXT:  SQL statement &quot;ALTER TABLE table_name_value OWNER TO owner_arg&quot;
  PL/pgSQL function change_owner_table_catalog(character varying,character varying) line 7 at SQL statement
  SQL state: 42P01</p>
  </blockquote>