Fix CDB_Overviews for cases that require explicit schema name

Fixes #218
This commit is contained in:
Javier Goizueta 2016-04-04 17:02:59 +02:00
parent aff7ae3e2e
commit c0262a05eb
2 changed files with 16 additions and 12 deletions

View File

@ -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
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,
cdb_usertables::regclass AS overview_table
(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;
$$ LANGUAGE SQL;
END
$$ LANGUAGE PLPGSQL;
-- Return existing overviews (if any) for multiple dataset tables.
-- Scope: public

View File

@ -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);