BUG #12766: Dump/Load of Materialized View with inlined SQL function fails - Mailing list pgsql-bugs

From felix.buenemann@gmail.com
Subject BUG #12766: Dump/Load of Materialized View with inlined SQL function fails
Date
Msg-id 20150213000055.2584.16773@wrigleys.postgresql.org
Whole thread Raw
Responses Re: BUG #12766: Dump/Load of Materialized View with inlined SQL function fails  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-bugs
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

pgsql-bugs by date:

Previous
From: Moe
Date:
Subject: Re: BUG #12760: Lateral files with more than 2 laterals
Next
From: Tom Lane
Date:
Subject: Re: BUG #12766: Dump/Load of Materialized View with inlined SQL function fails