The following bug has been logged on the website:
Bug reference: 12766
Logged by: Felix Buenemann
Email address: felix.buenemann@gmail.com
PostgreSQL version: 9.4.1
Operating system: Mac OS X 10.10.2
Description:
pg_dump dumps materialized views in the wrong order, if the view is
alphabetically sorted before a table that it references indirectly through a
stored procedure in sql language.
The reason seems to be that pg_dump does not know about the indirect
dependency of the matview, so it doesn't reorder the tables/matviews
properly.
This leads to errors like this on restore:
psql:foo.sql:43: ERROR: relation "foo" does not exist
LINE 1: SELECT label FROM foo WHERE id = value;
^
QUERY: SELECT label FROM foo WHERE id = value;
CONTEXT: SQL function "foo_label" during inlining
Problematic dump from error above:
https://gist.github.com/056f157a200e334dc5b0
Minimal testcase (thanks to RhodiumToad on IRC):
http://pgsql.privatepaste.com/cc80393e25