view schema/updates/1005/01.search-only-valid-bottleneck.sql @ 4808:db450fcc8ed7

client: add title for the exported image
author Fadi Abbud <fadi.abbud@intevation.de>
date Tue, 29 Oct 2019 11:04:14 +0100
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;
$$;