Merge remote-tracking branch 'origin/release_v1_api_functions' into release_v1_api_functions_aug_use

This commit is contained in:
John Krauss
2016-04-21 12:32:34 -04:00
3 changed files with 44 additions and 0 deletions

View File

@@ -151,3 +151,25 @@ BEGIN
END;
$$ LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION cdb_observatory._OBS_GetRelatedColumn(columns_ids text[], reltype text )
RETURNS TEXT[]
AS $$
DECLARE
result TEXT[];
BEGIN
EXECUTE '
With ids as (
select row_number() over() as no, id from (select unnest($1) as id) t
)
select array_agg(target_id order by no)
FROM ids
LEFT JOIN observatory.obs_column_to_column
on source_id = id
where reltype = $2 or reltype is null
'
INTO result
using columns_ids, reltype;
return result;
END;
$$ LANGUAGE plpgsql;

View File

@@ -127,6 +127,19 @@ SELECT
SELECT vals[1] As mandarin_orange
(1 row)
SELECT cdb_observatory._OBS_GetRelatedColumn(
Array[
'"es.ine".pop_0_4',
'"us.census.acs".B01001001',
'"us.census.acs".B01001002'
],
'denominator'
);
_obs_getrelatedcolumn
-------------------------------------------------------------
{"\"es.ine\".total_pop",NULL,"\"us.census.acs\".B01001001"}
(1 row)
\i test/sql/drop_fixtures.sql
SET client_min_messages TO NOTICE;
\set ECHO none

View File

@@ -75,4 +75,13 @@ SELECT
Array['mandarin_orange']
);
SELECT cdb_observatory._OBS_GetRelatedColumn(
Array[
'"es.ine".pop_0_4',
'"us.census.acs".B01001001',
'"us.census.acs".B01001002'
],
'denominator'
);
\i test/sql/drop_fixtures.sql