Fully qualify function names
This commit is contained in:
parent
67ae37fb67
commit
b1b69113a2
@ -123,7 +123,7 @@ CREATE OR REPLACE FUNCTION cdb_observatory._TestArea()
|
|||||||
AS $$
|
AS $$
|
||||||
BEGIN
|
BEGIN
|
||||||
-- Buffer NYC point by 500 meters
|
-- Buffer NYC point by 500 meters
|
||||||
RETURN ST_Buffer(_TestPoint()::geography, 500)::geometry;
|
RETURN ST_Buffer(cdb_observatory._TestPoint()::geography, 500)::geometry;
|
||||||
|
|
||||||
END;
|
END;
|
||||||
$$ LANGUAGE plpgsql;
|
$$ LANGUAGE plpgsql;
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
-- Creates a table of demographic snapshot
|
-- Creates a table of demographic snapshot
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION 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 '2009 - 2013', geometry_level text default '"us.census.tiger".block_group' )
|
||||||
RETURNS TABLE(
|
RETURNS TABLE(
|
||||||
total_pop NUMERIC,
|
total_pop NUMERIC,
|
||||||
male_pop NUMERIC,
|
male_pop NUMERIC,
|
||||||
@ -212,9 +212,9 @@ BEGIN
|
|||||||
SELECT
|
SELECT
|
||||||
dimension As names,
|
dimension As names,
|
||||||
dimension_value As vals
|
dimension_value As vals
|
||||||
FROM OBS_GetCensus($1,$2,$3,$4)
|
FROM cdb_observatory.OBS_GetCensus($1,$2,$3,$4)
|
||||||
)' ||
|
)' ||
|
||||||
OBS_BuildSnapshotQuery(target_cols) ||
|
cdb_observatory.OBS_BuildSnapshotQuery(target_cols) ||
|
||||||
' FROM a';
|
' FROM a';
|
||||||
|
|
||||||
RETURN QUERY
|
RETURN QUERY
|
||||||
@ -233,7 +233,7 @@ $$ LANGUAGE plpgsql;
|
|||||||
|
|
||||||
--Returns arrays of values for the given census dimension names for a given
|
--Returns arrays of values for the given census dimension names for a given
|
||||||
--point or polygon
|
--point or polygon
|
||||||
CREATE OR REPLACE FUNCTION OBS_GetCensus(
|
CREATE OR REPLACE FUNCTION cdb_observatory.OBS_GetCensus(
|
||||||
geom geometry,
|
geom geometry,
|
||||||
dimension_names text[],
|
dimension_names text[],
|
||||||
time_span text DEFAULT '2009 - 2013',
|
time_span text DEFAULT '2009 - 2013',
|
||||||
@ -245,17 +245,17 @@ DECLARE
|
|||||||
ids text[];
|
ids text[];
|
||||||
BEGIN
|
BEGIN
|
||||||
|
|
||||||
ids := OBS_LookupCensusHuman(dimension_names);
|
ids := cdb_observatory.OBS_LookupCensusHuman(dimension_names);
|
||||||
|
|
||||||
RETURN QUERY
|
RETURN QUERY
|
||||||
SELECT names, vals FROM OBS_Get(geom, ids, time_span, geometry_level);
|
SELECT names, vals FROM cdb_observatory.OBS_Get(geom, ids, time_span, geometry_level);
|
||||||
END;
|
END;
|
||||||
$$ LANGUAGE plpgsql;
|
$$ LANGUAGE plpgsql;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- Base augmentation fucntion.
|
-- Base augmentation fucntion.
|
||||||
CREATE OR REPLACE FUNCTION OBS_Get(
|
CREATE OR REPLACE FUNCTION cdb_observatory.OBS_Get(
|
||||||
geom geometry,
|
geom geometry,
|
||||||
column_ids text[],
|
column_ids text[],
|
||||||
time_span text,
|
time_span text,
|
||||||
@ -268,10 +268,10 @@ DECLARE
|
|||||||
geom_table_name text;
|
geom_table_name text;
|
||||||
names text[];
|
names text[];
|
||||||
query text;
|
query text;
|
||||||
data_table_info OBS_ColumnData[];
|
data_table_info cdb_observatory.OBS_ColumnData[];
|
||||||
BEGIN
|
BEGIN
|
||||||
|
|
||||||
geom_table_name := OBS_GeomTable(geom, geometry_level);
|
geom_table_name := cdb_observatory.OBS_GeomTable(geom, geometry_level);
|
||||||
|
|
||||||
IF geom_table_name IS NULL
|
IF geom_table_name IS NULL
|
||||||
THEN
|
THEN
|
||||||
@ -279,7 +279,7 @@ BEGIN
|
|||||||
RETURN QUERY SELECT '{}'::text[], '{}'::NUMERIC[];
|
RETURN QUERY SELECT '{}'::text[], '{}'::NUMERIC[];
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
data_table_info := OBS_GetColumnData(geometry_level,
|
data_table_info := cdb_observatory.OBS_GetColumnData(geometry_level,
|
||||||
column_ids,
|
column_ids,
|
||||||
time_span);
|
time_span);
|
||||||
|
|
||||||
@ -288,13 +288,13 @@ BEGIN
|
|||||||
|
|
||||||
IF ST_GeometryType(geom) = 'ST_Point'
|
IF ST_GeometryType(geom) = 'ST_Point'
|
||||||
THEN
|
THEN
|
||||||
results := OBS_GetPoints(geom,
|
results := cdb_observatory.OBS_GetPoints(geom,
|
||||||
geom_table_name,
|
geom_table_name,
|
||||||
data_table_info);
|
data_table_info);
|
||||||
|
|
||||||
ELSIF ST_GeometryType(geom) IN ('ST_Polygon', 'ST_MultiPolygon')
|
ELSIF ST_GeometryType(geom) IN ('ST_Polygon', 'ST_MultiPolygon')
|
||||||
THEN
|
THEN
|
||||||
results := OBS_GetPolygons(geom,
|
results := cdb_observatory.OBS_GetPolygons(geom,
|
||||||
geom_table_name,
|
geom_table_name,
|
||||||
data_table_info);
|
data_table_info);
|
||||||
END IF;
|
END IF;
|
||||||
@ -311,10 +311,10 @@ $$ LANGUAGE plpgsql;
|
|||||||
|
|
||||||
-- If the variable of interest is just a rate return it as such,
|
-- If the variable of interest is just a rate return it as such,
|
||||||
-- otherwise normalize it to the census block area and return that
|
-- otherwise normalize it to the census block area and return that
|
||||||
CREATE OR REPLACE FUNCTION OBS_GetPoints(
|
CREATE OR REPLACE FUNCTION cdb_observatory.OBS_GetPoints(
|
||||||
geom geometry,
|
geom geometry,
|
||||||
geom_table_name text,
|
geom_table_name text,
|
||||||
data_table_info OBS_ColumnData[]
|
data_table_info cdb_observatory.OBS_ColumnData[]
|
||||||
)
|
)
|
||||||
RETURNS NUMERIC[]
|
RETURNS NUMERIC[]
|
||||||
AS $$
|
AS $$
|
||||||
@ -392,10 +392,10 @@ BEGIN
|
|||||||
END;
|
END;
|
||||||
$$ LANGUAGE plpgsql;
|
$$ LANGUAGE plpgsql;
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION OBS_GetPolygons(
|
CREATE OR REPLACE FUNCTION cdb_observatory.OBS_GetPolygons(
|
||||||
geom geometry,
|
geom geometry,
|
||||||
geom_table_name text,
|
geom_table_name text,
|
||||||
data_table_info OBS_ColumnData[]
|
data_table_info cdb_observatory.OBS_ColumnData[]
|
||||||
)
|
)
|
||||||
RETURNS NUMERIC[]
|
RETURNS NUMERIC[]
|
||||||
AS $$
|
AS $$
|
||||||
@ -562,7 +562,7 @@ target_cols := Array[
|
|||||||
EXECUTE
|
EXECUTE
|
||||||
$query$
|
$query$
|
||||||
SELECT (categories)[1]
|
SELECT (categories)[1]
|
||||||
FROM OBS_GetCategories(
|
FROM cdb_observatory.OBS_GetCategories(
|
||||||
$1,
|
$1,
|
||||||
Array['"us.census.spielman_singleton_segments".X10'],
|
Array['"us.census.spielman_singleton_segments".X10'],
|
||||||
$2)
|
$2)
|
||||||
@ -587,7 +587,7 @@ target_cols := Array[
|
|||||||
FROM a)
|
FROM a)
|
||||||
SELECT $4, percentiles.*
|
SELECT $4, percentiles.*
|
||||||
FROM percentiles
|
FROM percentiles
|
||||||
$query$, OBS_BuildSnapshotQuery(target_cols));
|
$query$, cdb_observatory.OBS_BuildSnapshotQuery(target_cols));
|
||||||
|
|
||||||
RETURN QUERY
|
RETURN QUERY
|
||||||
EXECUTE
|
EXECUTE
|
||||||
@ -599,7 +599,7 @@ $$ LANGUAGE plpgsql;
|
|||||||
|
|
||||||
--Get categorical variables from point
|
--Get categorical variables from point
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION 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',
|
geometry_level text DEFAULT '"us.census.tiger".block_group',
|
||||||
@ -612,10 +612,10 @@ DECLARE
|
|||||||
names text[];
|
names text[];
|
||||||
results text[];
|
results text[];
|
||||||
query text;
|
query text;
|
||||||
data_table_info OBS_ColumnData[];
|
data_table_info cdb_observatory.OBS_ColumnData[];
|
||||||
BEGIN
|
BEGIN
|
||||||
|
|
||||||
geom_table_name := OBS_GeomTable(geom, geometry_level);
|
geom_table_name := cdb_observatory.OBS_GeomTable(geom, geometry_level);
|
||||||
|
|
||||||
IF geom_table_name IS NULL
|
IF geom_table_name IS NULL
|
||||||
THEN
|
THEN
|
||||||
@ -623,7 +623,7 @@ BEGIN
|
|||||||
RETURN QUERY SELECT '{}'::text[], '{}'::text[];
|
RETURN QUERY SELECT '{}'::text[], '{}'::text[];
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
data_table_info := OBS_GetColumnData(geometry_level,
|
data_table_info := cdb_observatory.OBS_GetColumnData(geometry_level,
|
||||||
dimension_names,
|
dimension_names,
|
||||||
time_span);
|
time_span);
|
||||||
|
|
||||||
|
@ -84,23 +84,23 @@ SELECT
|
|||||||
-- {12996.8172420752}
|
-- {12996.8172420752}
|
||||||
|
|
||||||
SELECT
|
SELECT
|
||||||
OBS_GetPolygons(
|
cdb_observatory.OBS_GetPolygons(
|
||||||
_TestArea(),
|
cdb_observatory._TestArea(),
|
||||||
'obs_a92e1111ad3177676471d66bb8036e6d057f271b'::text, -- see example in obs_geomtable
|
'obs_a92e1111ad3177676471d66bb8036e6d057f271b'::text, -- see example in obs_geomtable
|
||||||
Array[('total_pop','obs_ab038198aaab3f3cb055758638ee4de28ad70146','sum')::OBS_ColumnData]
|
Array[('total_pop','obs_ab038198aaab3f3cb055758638ee4de28ad70146','sum')::cdb_observatory.OBS_ColumnData]
|
||||||
);
|
);
|
||||||
|
|
||||||
-- see what happens around null island
|
-- see what happens around null island
|
||||||
SELECT
|
SELECT
|
||||||
OBS_GetPolygons(
|
cdb_observatory.OBS_GetPolygons(
|
||||||
ST_Buffer(CDB_LatLng(0, 0)::geography, 500)::geometry,
|
ST_Buffer(CDB_LatLng(0, 0)::geography, 500)::geometry,
|
||||||
'obs_a92e1111ad3177676471d66bb8036e6d057f271b'::text, -- see example in obs_geomtable
|
'obs_a92e1111ad3177676471d66bb8036e6d057f271b'::text, -- see example in obs_geomtable
|
||||||
Array[('total_pop','obs_ab038198aaab3f3cb055758638ee4de28ad70146','sum')::OBS_ColumnData]
|
Array[('total_pop','obs_ab038198aaab3f3cb055758638ee4de28ad70146','sum')::cdb_observatory.OBS_ColumnData]
|
||||||
);
|
);
|
||||||
|
|
||||||
SELECT * FROM
|
SELECT * FROM
|
||||||
cdb_observatory.OBS_GetSegmentSnapshot(
|
cdb_observatory.OBS_GetSegmentSnapshot(
|
||||||
_TestPoint(),
|
cdb_observatory._TestPoint(),
|
||||||
'"us.census.tiger".census_tract'
|
'"us.census.tiger".census_tract'
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -113,7 +113,7 @@ SELECT * FROM
|
|||||||
|
|
||||||
SELECT * FROM
|
SELECT * FROM
|
||||||
cdb_observatory.OBS_GetCategories(
|
cdb_observatory.OBS_GetCategories(
|
||||||
_TestPoint(),
|
cdb_observatory._TestPoint(),
|
||||||
Array['"us.census.spielman_singleton_segments".X10'],
|
Array['"us.census.spielman_singleton_segments".X10'],
|
||||||
'"us.census.tiger".census_tract'
|
'"us.census.tiger".census_tract'
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user