view schema/updates/1005/01.search-only-valid-bottleneck.sql @ 4214:49564382ffff

Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 16 Aug 2019 13:15:34 +0200
parents da3ab68875e1
children
line wrap: on
line source

CREATE OR REPLACE FUNCTION search_bottlenecks(search_string text) RETURNS jsonb
  LANGUAGE plpgsql STABLE PARALLEL SAFE
  AS $$
DECLARE
  _result jsonb;
BEGIN
  SELECT COALESCE(json_agg(r),'[]')
    INTO _result
    FROM (SELECT objnam AS name,
                 ST_AsGeoJSON(ST_Envelope(area::geometry))::json AS geom,
                 'bottleneck' AS type
            FROM waterway.bottlenecks
            WHERE objnam ILIKE '%' || search_string || '%'
              AND validity @> 'now'::timestamptz
          ORDER BY name) r;
  RETURN _result;
END;
$$;