From c595e45c11a1272664f056ca0c589bd7193f4599 Mon Sep 17 00:00:00 2001 From: Javier Goizueta Date: Thu, 14 Apr 2016 17:32:18 +0200 Subject: [PATCH] Add _vovw_count columnt to tables for which overviews are created Initially we planned to add this column to the queries sent to the tiler only, but that makes the column hard to access from the editor. --- scripts-available/CDB_Overviews.sql | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/scripts-available/CDB_Overviews.sql b/scripts-available/CDB_Overviews.sql index 04beae3..1285e3c 100644 --- a/scripts-available/CDB_Overviews.sql +++ b/scripts-available/CDB_Overviews.sql @@ -718,6 +718,7 @@ DECLARE overview_z integer; overview_tables REGCLASS[]; overviews_step integer := 1; + has_counter_column boolean; BEGIN -- Determine the referece zoom level EXECUTE 'SELECT ' || quote_ident(refscale_strategy::text) || Format('(''%s'', %s);', reloid, tolerance_px) INTO ref_z; @@ -743,6 +744,17 @@ BEGIN SELECT array_append(overview_tables, base_rel) INTO overview_tables; END LOOP; + IF overview_tables IS NOT NULL AND array_length(overview_tables, 1) > 0 THEN + SELECT EXISTS ( + SELECT * FROM CDB_ColumnNames(reloid) as colname WHERE colname = '_vovw_count' + ) INTO has_counter_column; + IF NOT has_counter_column THEN + EXECUTE Format(' + ALTER TABLE %s ADD COLUMN _vovw_count integer DEFAULT 1; + ', reloid); + END IF; + END IF; + RETURN overview_tables; END; $$ LANGUAGE PLPGSQL;