diff --git a/src/pg/sql/40_observatory_utility.sql b/src/pg/sql/40_observatory_utility.sql index f132d85..6ed44b2 100644 --- a/src/pg/sql/40_observatory_utility.sql +++ b/src/pg/sql/40_observatory_utility.sql @@ -95,7 +95,8 @@ BEGIN aggregate, name, type, - c.description + c.description, + $1 AS boundary_id FROM column_ids, observatory.OBS_column c, observatory.OBS_column_table ct, observatory.OBS_table t WHERE column_ids.column_id = c.id AND c.id = ct.column_id diff --git a/src/pg/sql/41_observatory_augmentation.sql b/src/pg/sql/41_observatory_augmentation.sql index 414b10e..768626f 100644 --- a/src/pg/sql/41_observatory_augmentation.sql +++ b/src/pg/sql/41_observatory_augmentation.sql @@ -155,20 +155,25 @@ DECLARE data_table_info json[]; BEGIN - geom_table_name := cdb_observatory._OBS_GeomTable(geom, geometry_level); - - IF geom_table_name IS NULL - THEN - RAISE NOTICE 'Point % is outside of the data region', ST_AsText(geom); - RETURN QUERY SELECT '{}'::text[], '{}'::NUMERIC[]; - END IF; - EXECUTE 'SELECT array_agg(_obs_getcolumndata) FROM cdb_observatory._OBS_GetColumnData($1, $2, $3);' INTO data_table_info USING geometry_level, column_ids, time_span; + IF geometry_level IS NULL THEN + geometry_level = data_table_info[1]->>'boundary_id'; + END IF; + + geom_table_name := cdb_observatory._OBS_GeomTable(geom, geometry_level); + + IF geom_table_name IS NULL + THEN + RAISE NOTICE 'Point % is outside of the data region', ST_AsText(geom); + -- TODO this should return JSON + RETURN QUERY SELECT '{}'::text[], '{}'::NUMERIC[]; + END IF; + IF data_table_info IS NULL THEN RAISE NOTICE 'Cannot find data table for boundary ID %, column_ids %, and time_span %', geometry_level, column_ids, time_span; END IF;