title: pg_restore fails when trying to create function referencing table that does not exist yet
body: <p>I've used <code>pg_dump --no-privileges --format custom --compress=0 some_database &gt; my-dump.pgdump</code> to dump a database, but I'm running into issues when I try to restore it.</p>
  
  <p>Specifically, it appears to be loading function definitions before table definitions:</p>
  
  <pre><code>$ pg_restore ./my-dump.pgdump
  …
  
  create function my_function() returns …
  language sql $$
    select …
    from some_table
    where …
  $$;
  
  … later in the dump …
  
  create table some_table ( … );
  
  …
  </code></pre>
  
  <p>Which causes an error when I try to restore the dump:</p>
  
  <pre><code>pg_restore: [archiver (db)] Error while PROCESSING TOC:
  pg_restore: [archiver (db)] Error from TOC entry 4863; 0 16735 TABLE DATA some_table some_database
  pg_restore: [archiver (db)] COPY failed for table "some_table": ERROR:  relation "some_table" does not exist
  LINE 3:                     from some_table
                                   ^
  QUERY:
                      select …
                      from some_table
                      where …
  
  CONTEXT:  SQL function "my_function" during inlining
  </code></pre>
  
  <p>What's going on here? How can I trick <code>pg_dump</code> / <code>pg_restore</code> into doing things in the correct order?</p>