Merge branch 'release_v1_api_functions' into release_v1_api_functions_add_boundary_functions
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
|
||||
-- return a table that contains a string match based on input
|
||||
-- TODO: implement search for timespan
|
||||
|
||||
@@ -42,3 +41,79 @@ BEGIN
|
||||
|
||||
END;
|
||||
$$ LANGUAGE plpgsql IMMUTABLE;
|
||||
|
||||
-- Functions used to search the observatory for measures
|
||||
--------------------------------------------------------------------------------
|
||||
-- TODO allow the user to specify the boundary to search for measures
|
||||
--
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_observatory.OBS_Search(
|
||||
search_term text,
|
||||
relevant_boundary text DEFAULT null
|
||||
)
|
||||
RETURNS TABLE(id text, description text, name text, aggregate text, source text) as $$
|
||||
DECLARE
|
||||
boundary_term text;
|
||||
BEGIN
|
||||
IF relevant_boundary then
|
||||
boundary_term = '';
|
||||
else
|
||||
boundary_term = '';
|
||||
END IF;
|
||||
|
||||
RETURN QUERY
|
||||
EXECUTE format($string$
|
||||
SELECT id, description,
|
||||
name,
|
||||
aggregate,
|
||||
replace(split_part(id,'".', 1),'"', '') source
|
||||
FROM observatory.OBS_column
|
||||
where name ilike '%%' || %L || '%%'
|
||||
or description ilike '%%' || %L || '%%'
|
||||
%s
|
||||
$string$, search_term, search_term,boundary_term);
|
||||
RETURN;
|
||||
END
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
|
||||
-- Functions to return the geometry levels that a point is part of
|
||||
--------------------------------------------------------------------------------
|
||||
-- TODO add test response
|
||||
|
||||
CREATE OR REPLACE FUNCTION OBS_GetAvailableBoundaries(
|
||||
geom geometry,
|
||||
timespan text DEFAULT null)
|
||||
RETURNS TABLE(boundary_id text, description text, time_span text, tablename text) as $$
|
||||
DECLARE
|
||||
timespan_query TEXT DEFAULT '';
|
||||
BEGIN
|
||||
|
||||
IF time_span != null THEN
|
||||
timespan_query = format('AND timespan = %L', time_span);
|
||||
END IF;
|
||||
|
||||
RETURN QUERY
|
||||
EXECUTE
|
||||
$string$
|
||||
select
|
||||
column_id,
|
||||
obs_column.description,
|
||||
timespan,
|
||||
tablename
|
||||
FROM
|
||||
observatory.OBS_table,
|
||||
observatory.OBS_column_table,
|
||||
observatory.OBS_column
|
||||
WHERE
|
||||
observatory.OBS_column_table.column_id = observatory.obs_column.id AND
|
||||
observatory.OBS_column_table.table_id = observatory.obs_table.id
|
||||
AND
|
||||
observatory.OBS_column.type='Geometry'
|
||||
AND
|
||||
$1 && bounds::box2d
|
||||
$string$ || timespan_query
|
||||
USING geom
|
||||
RETURN;
|
||||
END
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
Reference in New Issue
Block a user