switch optional defaults to null
This commit is contained in:
parent
b665773b50
commit
c7b74b068f
@ -22,12 +22,23 @@
|
|||||||
|
|
||||||
-- Creates a table of demographic snapshot
|
-- Creates a table of demographic snapshot
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION cdb_observatory.OBS_GetDemographicSnapshot(geom geometry, time_span text default '2009 - 2013', geometry_level text default 'us.census.tiger.block_group')
|
CREATE OR REPLACE FUNCTION cdb_observatory.OBS_GetDemographicSnapshot(geom geometry,
|
||||||
|
time_span text DEFAULT NULL,
|
||||||
|
boundary_id text DEFAULT NULL)
|
||||||
RETURNS SETOF JSON
|
RETURNS SETOF JSON
|
||||||
AS $$
|
AS $$
|
||||||
DECLARE
|
DECLARE
|
||||||
target_cols text[];
|
target_cols text[];
|
||||||
BEGIN
|
BEGIN
|
||||||
|
|
||||||
|
IF time_span IS NULL THEN
|
||||||
|
time_span = '2010 - 2014';
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
IF boundary_id IS NULL THEN
|
||||||
|
boundary_id = 'us.census.tiger.block_group';
|
||||||
|
END IF;
|
||||||
|
|
||||||
target_cols := Array['us.census.acs.B01001001',
|
target_cols := Array['us.census.acs.B01001001',
|
||||||
'us.census.acs.B01001002',
|
'us.census.acs.B01001002',
|
||||||
'us.census.acs.B01001026',
|
'us.census.acs.B01001026',
|
||||||
@ -114,12 +125,11 @@ AS $$
|
|||||||
'us.census.acs.B19001014',
|
'us.census.acs.B19001014',
|
||||||
'us.census.acs.B19001015',
|
'us.census.acs.B19001015',
|
||||||
'us.census.acs.B19001016',
|
'us.census.acs.B19001016',
|
||||||
'us.census.acs.B19001017',
|
'us.census.acs.B19001017'];
|
||||||
NULL]; -- land_area
|
|
||||||
RETURN QUERY
|
RETURN QUERY
|
||||||
EXECUTE
|
EXECUTE
|
||||||
'select * from cdb_observatory._OBS_Get($1, $2, $3, $4 )'
|
'select * from cdb_observatory._OBS_Get($1, $2, $3, $4 )'
|
||||||
USING geom, target_cols, time_span, geometry_level
|
USING geom, target_cols, time_span, boundary_id
|
||||||
RETURN;
|
RETURN;
|
||||||
END;
|
END;
|
||||||
$$ LANGUAGE plpgsql;
|
$$ LANGUAGE plpgsql;
|
||||||
@ -548,7 +558,7 @@ $$ LANGUAGE plpgsql;
|
|||||||
|
|
||||||
CREATE OR REPLACE FUNCTION cdb_observatory.OBS_GetSegmentSnapshot(
|
CREATE OR REPLACE FUNCTION cdb_observatory.OBS_GetSegmentSnapshot(
|
||||||
geom geometry,
|
geom geometry,
|
||||||
geometry_level text DEFAULT 'us.census.tiger.census_tract'
|
boundary_id text DEFAULT NULL
|
||||||
)
|
)
|
||||||
RETURNS JSON
|
RETURNS JSON
|
||||||
AS $$
|
AS $$
|
||||||
@ -560,6 +570,9 @@ DECLARE
|
|||||||
q Text;
|
q Text;
|
||||||
segment_name Text;
|
segment_name Text;
|
||||||
BEGIN
|
BEGIN
|
||||||
|
IF boundary_id IS NULL THEN
|
||||||
|
boundary_id = 'us.census.tiger.census_tract';
|
||||||
|
END IF;
|
||||||
target_cols := Array[
|
target_cols := Array[
|
||||||
'us.census.acs.B01001001_quantile',
|
'us.census.acs.B01001001_quantile',
|
||||||
'us.census.acs.B01001002_quantile',
|
'us.census.acs.B01001002_quantile',
|
||||||
@ -617,7 +630,7 @@ target_cols := Array[
|
|||||||
LIMIT 1
|
LIMIT 1
|
||||||
$query$
|
$query$
|
||||||
INTO segment_name
|
INTO segment_name
|
||||||
USING geom, geometry_level;
|
USING geom, boundary_id;
|
||||||
|
|
||||||
q :=
|
q :=
|
||||||
format($query$
|
format($query$
|
||||||
@ -642,7 +655,7 @@ target_cols := Array[
|
|||||||
EXECUTE
|
EXECUTE
|
||||||
q
|
q
|
||||||
into result
|
into result
|
||||||
USING geom, target_cols, geometry_level, segment_name;
|
USING geom, target_cols, boundary_id, segment_name;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
@ -654,8 +667,8 @@ $$ LANGUAGE plpgsql;
|
|||||||
CREATE OR REPLACE FUNCTION cdb_observatory._OBS_GetCategories(
|
CREATE OR REPLACE FUNCTION cdb_observatory._OBS_GetCategories(
|
||||||
geom geometry,
|
geom geometry,
|
||||||
dimension_names text[],
|
dimension_names text[],
|
||||||
geometry_level text DEFAULT 'us.census.tiger.block_group',
|
boundary_id text DEFAULT NULL,
|
||||||
time_span text DEFAULT '2009 - 2013'
|
time_span text DEFAULT NULL
|
||||||
)
|
)
|
||||||
RETURNS SETOF JSON as $$
|
RETURNS SETOF JSON as $$
|
||||||
DECLARE
|
DECLARE
|
||||||
@ -667,7 +680,15 @@ DECLARE
|
|||||||
data_table_info json[];
|
data_table_info json[];
|
||||||
BEGIN
|
BEGIN
|
||||||
|
|
||||||
geom_table_name := cdb_observatory._OBS_GeomTable(geom, geometry_level);
|
IF time_span IS NULL THEN
|
||||||
|
time_span = '2009 - 2013';
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
IF boundary_id IS NULL THEN
|
||||||
|
boundary_id = 'us.census.tiger.block_group';
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
geom_table_name := cdb_observatory._OBS_GeomTable(geom, boundary_id);
|
||||||
|
|
||||||
IF geom_table_name IS NULL
|
IF geom_table_name IS NULL
|
||||||
THEN
|
THEN
|
||||||
@ -680,7 +701,7 @@ BEGIN
|
|||||||
$2,
|
$2,
|
||||||
$3);'
|
$3);'
|
||||||
INTO data_table_info
|
INTO data_table_info
|
||||||
using geometry_level, dimension_names, time_span;
|
USING boundary_id, dimension_names, time_span;
|
||||||
|
|
||||||
|
|
||||||
EXECUTE
|
EXECUTE
|
||||||
|
Loading…
Reference in New Issue
Block a user