diff --git a/backup/dependencies.go b/backup/dependencies.go index 54ac5c322..6636bc101 100644 --- a/backup/dependencies.go +++ b/backup/dependencies.go @@ -278,12 +278,13 @@ func GetDependencies(connectionPool *dbconn.DBConn, backupSet map[UniqueID]bool, query := `SELECT coalesce(id1.refclassid, d.classid) AS classid, coalesce(id1.refobjid, d.objid) AS objid, - coalesce(id2.refclassid, d.refclassid) AS refclassid, - coalesce(id2.refobjid, d.refobjid) AS refobjid + coalesce(id3.refclassid, id2.refclassid, d.refclassid) AS refclassid, + coalesce(id3.refobjid, id2.refobjid, d.refobjid) AS refobjid FROM pg_depend d -- link implicit objects, using objid and refobjid, to the objects that created them LEFT JOIN pg_depend id1 ON (d.objid = id1.objid and d.classid = id1.classid and id1.deptype='i') LEFT JOIN pg_depend id2 ON (d.refobjid = id2.objid and d.refclassid = id2.classid and id2.deptype='i') +LEFT JOIN pg_depend id3 ON (id2.refobjid = id3.objid and id2.refclassid = id3.classid and id3.deptype='i') WHERE d.classid != 0 AND d.deptype != 'i' UNION diff --git a/integration/dependency_queries_test.go b/integration/dependency_queries_test.go index 5eab9d384..4e646b427 100644 --- a/integration/dependency_queries_test.go +++ b/integration/dependency_queries_test.go @@ -212,6 +212,25 @@ object-relational database management system');`) Expect(functionDeps[funcEntry]).To(HaveKey(compositeEntry)) Expect(functionDeps[funcEntry]).To(HaveKey(baseEntry)) }) + It("construct dependencies correctly for a function dependent on an array of relation row's type", func() { + testhelper.AssertQueryRuns(connectionPool, "CREATE TABLE public.some_table(a int, b int)") + defer testhelper.AssertQueryRuns(connectionPool, "DROP TABLE public.some_table CASCADE") + testhelper.AssertQueryRuns(connectionPool, "CREATE FUNCTION public.some_function(arg public.some_table[]) RETURNS int AS $$ SELECT 42; $$ LANGUAGE SQL;") + defer testhelper.AssertQueryRuns(connectionPool, "DROP FUNCTION public.some_function(arg public.some_table[]);") + + functionOid := testutils.OidFromObjectName(connectionPool, "public", "some_function", backup.TYPE_FUNCTION) + funcEntry := backup.UniqueID{ClassID: backup.PG_PROC_OID, Oid: functionOid} + tableOid := testutils.OidFromObjectName(connectionPool, "public", "some_table", backup.TYPE_RELATION) + tableEntry := backup.UniqueID{ClassID: backup.PG_CLASS_OID, Oid: tableOid} + backupSet := map[backup.UniqueID]bool{funcEntry: true, tableEntry: true} + tables := make([]backup.Table, 0) + + functionDeps := backup.GetDependencies(connectionPool, backupSet, tables) + + Expect(functionDeps).To(HaveLen(1)) + Expect(functionDeps[funcEntry]).To(HaveLen(1)) + Expect(functionDeps[funcEntry]).To(HaveKey(tableEntry)) + }) }) Describe("type dependencies", func() { var (