summaryrefslogtreecommitdiff
path: root/src/bin/pg_dump/pg_dump.c
diff options
context:
space:
mode:
authorStephen Frost <sfrost@snowman.net>2016-12-21 13:47:13 -0500
committerStephen Frost <sfrost@snowman.net>2016-12-21 13:47:13 -0500
commit542975a147525caa659ac08220b81c32a60f0a5c (patch)
tree8268184861c3d721981da48179394b28342a7ee6 /src/bin/pg_dump/pg_dump.c
parente45319bb7796e3ab8095da329a1f73d22aaa57c4 (diff)
Fix dumping of casts and transforms using built-in functions
In pg_dump.c dumpCast() and dumpTransform(), we would happily ignore the cast or transform if it happened to use a built-in function because we weren't including the information about built-in functions when querying pg_proc from getFuncs(). Modify the query in getFuncs() to also gather information about functions which are used by user-defined casts and transforms (where "user-defined" means "has an OID >= FirstNormalObjectId"). This also adds to the TAP regression tests for 9.6 and master to cover these types of objects. Back-patch all the way for casts, back to 9.5 for transforms. Discussion: https://www.postgresql.org/message-id/flat/20160504183952.GE10850%40tamriel.snowman.net
Diffstat (limited to 'src/bin/pg_dump/pg_dump.c')
-rw-r--r--src/bin/pg_dump/pg_dump.c46
1 files changed, 37 insertions, 9 deletions
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index bd2d977bf20..6b2a6c939bb 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -4978,8 +4978,11 @@ getFuncs(Archive *fout, int *numFuncs)
* 3. Otherwise, we normally exclude functions in pg_catalog. However, if
* they're members of extensions and we are in binary-upgrade mode then
* include them, since we want to dump extension members individually in
- * that mode. Also, in 9.6 and up, include functions in pg_catalog if
- * they have an ACL different from what's shown in pg_init_privs.
+ * that mode. Also, if they are used by casts or transforms then we need
+ * to gather the information about them, though they won't be dumped if
+ * they are built-in. Also, in 9.6 and up, include functions in
+ * pg_catalog if they have an ACL different from what's shown in
+ * pg_init_privs.
*/
if (fout->remoteVersion >= 90600)
{
@@ -5013,12 +5016,21 @@ getFuncs(Archive *fout, int *numFuncs)
"\n AND ("
"\n pronamespace != "
"(SELECT oid FROM pg_namespace "
- "WHERE nspname = 'pg_catalog')",
+ "WHERE nspname = 'pg_catalog')"
+ "\n OR EXISTS (SELECT 1 FROM pg_cast"
+ "\n WHERE pg_cast.oid > %u "
+ "\n AND p.oid = pg_cast.castfunc)"
+ "\n OR EXISTS (SELECT 1 FROM pg_transform"
+ "\n WHERE pg_transform.oid > %u AND "
+ "\n (p.oid = pg_transform.trffromsql"
+ "\n OR p.oid = pg_transform.trftosql))",
acl_subquery->data,
racl_subquery->data,
initacl_subquery->data,
initracl_subquery->data,
- username_subquery);
+ username_subquery,
+ g_last_builtin_oid,
+ g_last_builtin_oid);
if (dopt->binary_upgrade)
appendPQExpBufferStr(query,
"\n OR EXISTS(SELECT 1 FROM pg_depend WHERE "
@@ -5052,11 +5064,24 @@ getFuncs(Archive *fout, int *numFuncs)
"\n AND NOT EXISTS (SELECT 1 FROM pg_depend "
"WHERE classid = 'pg_proc'::regclass AND "
"objid = p.oid AND deptype = 'i')");
- appendPQExpBufferStr(query,
+ appendPQExpBuffer(query,
"\n AND ("
"\n pronamespace != "
"(SELECT oid FROM pg_namespace "
- "WHERE nspname = 'pg_catalog')");
+ "WHERE nspname = 'pg_catalog')"
+ "\n OR EXISTS (SELECT 1 FROM pg_cast"
+ "\n WHERE pg_cast.oid > '%u'::oid"
+ "\n AND p.oid = pg_cast.castfunc)",
+ g_last_builtin_oid);
+
+ if (fout->remoteVersion >= 90500)
+ appendPQExpBuffer(query,
+ "\n OR EXISTS (SELECT 1 FROM pg_transform"
+ "\n WHERE pg_transform.oid > '%u'::oid"
+ "\n AND (p.oid = pg_transform.trffromsql"
+ "\n OR p.oid = pg_transform.trftosql))",
+ g_last_builtin_oid);
+
if (dopt->binary_upgrade && fout->remoteVersion >= 90100)
appendPQExpBufferStr(query,
"\n OR EXISTS(SELECT 1 FROM pg_depend WHERE "
@@ -11871,7 +11896,8 @@ dumpCast(Archive *fout, CastInfo *cast)
{
funcInfo = findFuncByOid(cast->castfunc);
if (funcInfo == NULL)
- return;
+ exit_horribly(NULL, "unable to find function definition for OID %u",
+ cast->castfunc);
}
/*
@@ -11980,13 +12006,15 @@ dumpTransform(Archive *fout, TransformInfo *transform)
{
fromsqlFuncInfo = findFuncByOid(transform->trffromsql);
if (fromsqlFuncInfo == NULL)
- return;
+ exit_horribly(NULL, "unable to find function definition for OID %u",
+ transform->trffromsql);
}
if (OidIsValid(transform->trftosql))
{
tosqlFuncInfo = findFuncByOid(transform->trftosql);
if (tosqlFuncInfo == NULL)
- return;
+ exit_horribly(NULL, "unable to find function definition for OID %u",
+ transform->trftosql);
}
/* Make sure we are in proper schema (needed for getFormattedTypeName) */