diff --git a/scripts-available/CDB_Overviews.sql b/scripts-available/CDB_Overviews.sql index fe0562c..b223020 100644 --- a/scripts-available/CDB_Overviews.sql +++ b/scripts-available/CDB_Overviews.sql @@ -100,18 +100,21 @@ $$ LANGUAGE PLPGSQL VOLATILE; CREATE OR REPLACE FUNCTION CDB_Overviews(reloid REGCLASS) RETURNS TABLE(base_table REGCLASS, z integer, overview_table REGCLASS) AS $$ - -- FIXME: this will fail if the overview tables - -- require a explicit schema name - -- possible solutions: return table names as text instead of regclass - -- or add schema of reloid before casting to regclass - SELECT - reloid AS base_table, - _CDB_OverviewTableZ(cdb_usertables) AS z, - cdb_usertables::regclass AS overview_table - FROM CDB_UserTables() - WHERE _CDB_IsOverviewTableOf((SELECT relname FROM pg_class WHERE oid=reloid), cdb_usertables) - ORDER BY z; -$$ LANGUAGE SQL; + DECLARE + schema_name TEXT; + table_name TEXT; + BEGIN + -- TODO: review implementation of CDB_UserTables an suitability for this + SELECT * FROM _cdb_split_table_name(reloid) INTO schema_name, table_name; + RETURN QUERY SELECT + reloid AS base_table, + _CDB_OverviewTableZ(cdb_usertables) AS z, + (schema_name||'.'||cdb_usertables)::regclass AS overview_table + FROM CDB_UserTables() + WHERE _CDB_IsOverviewTableOf((SELECT relname FROM pg_class WHERE oid=reloid), cdb_usertables) + ORDER BY z; + END +$$ LANGUAGE PLPGSQL; -- Return existing overviews (if any) for multiple dataset tables. -- Scope: public diff --git a/test/CDB_OverviewsTest.sql b/test/CDB_OverviewsTest.sql index 1a0f924..74e164a 100644 --- a/test/CDB_OverviewsTest.sql +++ b/test/CDB_OverviewsTest.sql @@ -23,6 +23,7 @@ SELECT CDB_CreateOverviews('polyg_t'::regclass); SELECT CDB_CreateOverviews('column_types_t'::regclass); SELECT CDB_Overviews('base_t'::regclass); +SELECT CDB_Overviews('"public"."base_t"'::regclass); SELECT CDB_Overviews(ARRAY['base_t'::regclass, 'base_bare_t'::regclass]); SELECT CDB_Overviews('polyg_t'::regclass); SELECT CDB_Overviews('column_types_t'::regclass);