Mercurial > gemma
annotate schema/updates/1006/01.fix-search-only-valid-bottleneck.sql @ 4671:0cc339c4c356
fairway profile line use correct delta
author | Thomas Junk <thomas.junk@intevation.de> |
---|---|
date | Tue, 15 Oct 2019 15:44:07 +0200 |
parents | b10f210af325 |
children |
rev | line source |
---|---|
4021
b10f210af325
Fixed latest fix to search-bottlenecks
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
1 CREATE OR REPLACE FUNCTION search_bottlenecks(search_string text) RETURNS jsonb |
b10f210af325
Fixed latest fix to search-bottlenecks
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
2 LANGUAGE plpgsql STABLE PARALLEL SAFE |
b10f210af325
Fixed latest fix to search-bottlenecks
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
3 AS $$ |
b10f210af325
Fixed latest fix to search-bottlenecks
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
4 DECLARE |
b10f210af325
Fixed latest fix to search-bottlenecks
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
5 _result jsonb; |
b10f210af325
Fixed latest fix to search-bottlenecks
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
6 BEGIN |
b10f210af325
Fixed latest fix to search-bottlenecks
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
7 SELECT COALESCE(json_agg(r),'[]') |
b10f210af325
Fixed latest fix to search-bottlenecks
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
8 INTO _result |
b10f210af325
Fixed latest fix to search-bottlenecks
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
9 FROM (SELECT objnam AS name, |
b10f210af325
Fixed latest fix to search-bottlenecks
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
10 ST_AsGeoJSON(ST_Envelope(area::geometry))::json AS geom, |
b10f210af325
Fixed latest fix to search-bottlenecks
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
11 'bottleneck' AS type |
b10f210af325
Fixed latest fix to search-bottlenecks
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
12 FROM waterway.bottlenecks |
b10f210af325
Fixed latest fix to search-bottlenecks
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
13 WHERE objnam ILIKE '%' || search_string || '%' |
b10f210af325
Fixed latest fix to search-bottlenecks
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
14 AND validity @> now() |
b10f210af325
Fixed latest fix to search-bottlenecks
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
15 ORDER BY name) r; |
b10f210af325
Fixed latest fix to search-bottlenecks
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
16 RETURN _result; |
b10f210af325
Fixed latest fix to search-bottlenecks
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
17 END; |
b10f210af325
Fixed latest fix to search-bottlenecks
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
18 $$; |