title: Event trigger to change owner on CREATE
body: <p>I'm trying to create a PostgreSQL event trigger, that fires whenever a user creates anything (table, view, function, sequence...) and sets the owner of this newly created thing to a certain role.</p>
  
  <p>So far I have the even trigger itself, that fires on any CREATE command:</p>
  
  <pre><code>CREATE EVENT TRIGGER setOwnerToMyRole ON ddl_command_end
  WHEN tg_tag LIKE 'CREATE%'
  EXECUTE PROCEDURE setOwnerToMyRole();
  </code></pre>
  
  <p>But I am having problems with the function itself:</p>
  
  <pre><code>CREATE FUNCTION setOwnerToMyRole() RETURNS event_trigger LANGUAGE plpgsql
  AS $$ BEGIN
      ALTER &lt;type&gt; &lt;name&gt; OWNER TO myRole 
  END; $$;
  </code></pre>
  
  <p>How do I get the type (as in table, view, etc.) and how do i get the name of the newly created thing?</p>
  
  <hr>
  
  <p>edit:
  Looking at <a href="https://stackoverflow.com/questions/23454339/how-to-get-the-name-of-the-altered-table-in-a-postgres-event-trigger">this question</a> and <a href="https://stackoverflow.com/questions/23488228/how-to-get-sql-text-from-postgres-event-trigger">this question</a> and of course <a href="http://www.postgresql.org/docs/current/static/sql-createeventtrigger.html" rel="nofollow noreferrer">CREATE EVENT TRIGGER</a> and <a href="http://www.postgresql.org/docs/current/static/plpgsql-trigger.html" rel="nofollow noreferrer">Trigger Procedures</a>, this is currently not really possible :(</p>