1
0
mirror of https://github.com/postgres/postgres.git synced 2025-09-02 04:21:28 +03:00

Fix dumping of security_barrier views with circular dependencies.

If a view has circular dependencies, pg_dump splits it into a CREATE TABLE
and a CREATE RULE command to break the dependency loop.  However, if the
view has reloptions, those options cannot be applied in the CREATE TABLE
command, because views and tables have different allowed reloptions so
CREATE TABLE would reject them.  Instead apply the reloptions after the
CREATE RULE, using ALTER VIEW SET.
This commit is contained in:
Tom Lane
2012-08-21 15:18:36 -04:00
parent e0badf67e9
commit 1ace786878
3 changed files with 34 additions and 6 deletions

View File

@@ -5062,6 +5062,16 @@ getRules(Archive *fout, int *numRules)
}
else
ruleinfo[i].separate = true;
/*
* If we're forced to break a dependency loop by dumping a view as a
* table and separate _RETURN rule, we'll move the view's reloptions
* to the rule. (This is necessary because tables and views have
* different valid reloptions, so we can't apply the options until the
* backend knows it's a view.) Otherwise the rule's reloptions stay
* NULL.
*/
ruleinfo[i].reloptions = NULL;
}
PQclear(res);
@@ -13724,10 +13734,7 @@ dumpRule(Archive *fout, RuleInfo *rinfo)
*/
if (rinfo->ev_enabled != 'O')
{
appendPQExpBuffer(cmd, "ALTER TABLE %s.",
fmtId(tbinfo->dobj.namespace->dobj.name));
appendPQExpBuffer(cmd, "%s ",
fmtId(tbinfo->dobj.name));
appendPQExpBuffer(cmd, "ALTER TABLE %s ", fmtId(tbinfo->dobj.name));
switch (rinfo->ev_enabled)
{
case 'A':
@@ -13745,6 +13752,16 @@ dumpRule(Archive *fout, RuleInfo *rinfo)
}
}
/*
* Apply view's reloptions when its ON SELECT rule is separate.
*/
if (rinfo->reloptions)
{
appendPQExpBuffer(cmd, "ALTER VIEW %s SET (%s);\n",
fmtId(tbinfo->dobj.name),
rinfo->reloptions);
}
/*
* DROP must be fully qualified in case same name appears in pg_catalog
*/