Wrap functions in row_to_json

This commit is contained in:
Carla Iriberri 2016-04-19 17:31:08 +02:00
parent ad55625769
commit 077f8fedf5
2 changed files with 21 additions and 5 deletions

View File

@ -22,7 +22,15 @@
-- 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 '2009 - 2013', geometry_level text default '"us.census.tiger".block_group')
RETURNS json
AS $$
BEGIN
RETURN row_to_json(cdb_observatory._OBS_GetDemographicSnapshot(geom, time_span, geometry_level));
END;
$$ LANGUAGE plpgsql;
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(
total_pop NUMERIC,
male_pop NUMERIC,
@ -454,7 +462,15 @@ BEGIN
END;
$$ LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION OBS_GetSegmentSnapshot(
CREATE OR REPLACE FUNCTION OBS_GetSegmentSnapshot(geom geometry, geometry_level text default '"us.census.tiger".census_tract')
RETURNS json
AS $$
BEGIN
RETURN row_to_json(cdb_observatory._OBS_GetSegmentSnapshot(geom, geometry_level));
END;
$$ LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION _OBS_GetSegmentSnapshot(
geom geometry,
geometry_level text DEFAULT '"us.census.tiger".census_tract'
)

View File

@ -1,7 +1,7 @@
\i test/sql/load_fixtures.sql
--
SELECT * FROM
cdb_observatory.OBS_GetDemographicSnapshot(
cdb_observatory._OBS_GetDemographicSnapshot(
cdb_observatory._TestPoint(),
'2009 - 2013',
'"us.census.tiger".block_group'
@ -99,14 +99,14 @@ SELECT
);
SELECT * FROM
cdb_observatory.OBS_GetSegmentSnapshot(
cdb_observatory._OBS_GetSegmentSnapshot(
cdb_observatory._TestPoint(),
'"us.census.tiger".census_tract'
);
-- segmentation around null island
SELECT * FROM
cdb_observatory.OBS_GetSegmentSnapshot(
cdb_observatory._OBS_GetSegmentSnapshot(
CDB_LatLng(0, 0),
'"us.census.tiger".census_tract'
);