Overload CDB_Overviews to accept either a single table or an array

The result of CDB_Overviews has been expandend with a base_table column
This commit is contained in:
Javier Goizueta
2016-01-26 10:39:26 +01:00
parent 7033a8d9ac
commit 1ebaeb76ac
4 changed files with 75 additions and 3 deletions

View File

@@ -17,20 +17,24 @@ BEGIN
END;
$$ LANGUAGE PLPGSQL VOLATILE;
-- Return existing overviews (if any) for a given dataset table
-- Scope: public
-- Parameters
-- reloid: oid of the input table.
-- Return relation of overviews for the table with
-- z level of the overview and overview table, ordered by z.
-- the base table oid,
-- z level of the overview and overview table oid, ordered by z.
CREATE OR REPLACE FUNCTION CDB_Overviews(reloid REGCLASS)
RETURNS TABLE(z integer, overview_table 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,
substring(cdb_usertables from '\d+$')::integer as z,
cdb_usertables::regclass as overview_table
FROM CDB_UserTables()
@@ -38,6 +42,27 @@ AS $$
ORDER BY z;
$$ LANGUAGE SQL;
-- Return existing overviews (if any) for multiple dataset tables.
-- Scope: public
-- Parameters
-- tables: Array of input tables oids
-- Return relation of overviews for the table with
-- the base table oid,
-- z level of the overview and overview table oid, ordered by z.
-- Note: CDB_Overviews can be applied to the result of CDB_QueryTablesText
-- to obtain the overviews applicable to a query.
CREATE OR REPLACE FUNCTION CDB_Overviews(tables regclass[])
RETURNS TABLE(base_table REGCLASS, z integer, overview_table REGCLASS)
AS $$
SELECT
base_table::regclass AS base_table, substring(cdb_usertables from '\d+$')::integer as z,
cdb_usertables::regclass as overview_table
FROM
CDB_UserTables(), unnest(tables) base_table
WHERE cdb_usertables SIMILAR TO (SELECT relname FROM pg_class WHERE oid=base_table) || '_ov[\d]+'
ORDER BY base_table, z;
$$ LANGUAGE SQL;
-- Schema and relation names of a table given its reloid
-- Scope: private.
-- Parameters