diff --git a/src/pg/sql/40_observatory_utility.sql b/src/pg/sql/40_observatory_utility.sql index 38ba4a6..c3fc1f9 100644 --- a/src/pg/sql/40_observatory_utility.sql +++ b/src/pg/sql/40_observatory_utility.sql @@ -52,10 +52,17 @@ BEGIN EXECUTE ' WITH geomref AS ( SELECT t.table_id id - FROM observatory.OBS_column_to_column c2c, observatory.OBS_column_table t + FROM observatory.OBS_column_to_column c2c, + observatory.OBS_column c, + observatory.OBS_column_table geom_ct, + observatory.OBS_column_table data_ct, + observatory.OBS_table t WHERE c2c.reltype = ''geom_ref'' + AND c.column_id = c2c.target_id AND c2c.target_id = $1 - AND c2c.source_id = t.column_id + AND c2c.source_id = ct.column_id + ORDER BY weight DESC + LIMIT 1 ), column_ids as ( select row_number() over () as no, a.column_id as column_id from (select unnest($2) as column_id) a diff --git a/src/pg/sql/41_observatory_augmentation.sql b/src/pg/sql/41_observatory_augmentation.sql index ef78434..2310b49 100644 --- a/src/pg/sql/41_observatory_augmentation.sql +++ b/src/pg/sql/41_observatory_augmentation.sql @@ -219,6 +219,7 @@ BEGIN -- TODO we're assuming our geom_table has only one geom_ref column -- we *really* should pass in both geom_table_name and boundary_id + -- TODO tablename should not be passed here (use boundary_id) EXECUTE format('SELECT ct.colname FROM observatory.obs_column_to_column c2c, @@ -284,10 +285,11 @@ BEGIN query := query || format(' ]::numeric[] FROM observatory.%I - WHERE %I.geoid = %L + WHERE %I.%I = %L ', ((data_table_info)[1])->>'tablename', ((data_table_info)[1])->>'tablename', + geoid_colname, geoid ); @@ -332,16 +334,6 @@ DECLARE vals NUMERIC[]; BEGIN - IF boundary_id IS NULL THEN - -- TODO we should determine best boundary for this geom - boundary_id := 'us.census.tiger.block_group'; - END IF; - - IF time_span IS NULL THEN - -- TODO we should determine latest timespan for this measure - time_span := '2010 - 2014'; - END IF; - IF normalize ILIKE 'area' THEN measure_ids := ARRAY[measure_id]; ELSIF normalize ILIKE 'denominator' THEN