Adding OBS_search function and tests
This commit is contained in:
33
src/pg/sql/42_observatory_exploration.sql
Normal file
33
src/pg/sql/42_observatory_exploration.sql
Normal file
@@ -0,0 +1,33 @@
|
||||
-- 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(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 description,
|
||||
name,
|
||||
aggregate,
|
||||
replace(split_part(id,'".', 1),'"', '') source
|
||||
FROM observatory.OBS_column
|
||||
where name ilike '%%%s%%'
|
||||
or description ilike '%%%s%%'
|
||||
%s
|
||||
$string$, search_term, search_term,boundary_term);
|
||||
RETURN;
|
||||
END
|
||||
$$ LANGUAGE plpgsql;
|
||||
Reference in New Issue
Block a user