Skip to content

Commit 081df51

Browse files
committed
simplificação da função. osm-codes/SV#1
1 parent cf5c689 commit 081df51

File tree

1 file changed

+2
-13
lines changed

1 file changed

+2
-13
lines changed

src/pubLib05hcode-encdec.sql

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,8 @@
4646
-- -- -- -- -- -- -- -- -- --
4747
-- Wrap and helper functions:
4848

49-
CREATE or replace FUNCTION str_geouri_decode(uri text) RETURNS float[] as $f$
50-
SELECT
51-
CASE
52-
WHEN cardinality(a)=2 AND u IS NULL THEN a || array[null,null]::float[]
53-
WHEN cardinality(a)=3 AND u IS NULL THEN a || array[null]::float[]
54-
WHEN cardinality(a)=2 AND u IS NOT NULL THEN a || array[null,u]::float[]
55-
WHEN cardinality(a)=3 AND u IS NOT NULL THEN a || array[u]::float[]
56-
ELSE NULL
57-
END
58-
FROM (
59-
SELECT regexp_split_to_array(regexp_replace(uri,'^geo:(olc:|ghs:)?|;.+$','','ig'),',')::float[] AS a,
60-
(regexp_match(uri,';u=([0-9\.]+)'))[1] AS u
61-
) t
49+
CREATE OR REPLACE FUNCTION str_geouri_decode(uri TEXT) RETURNS float[] AS $f$
50+
SELECT regexp_match(uri,'^geo:(?:olc:|ghs:)?([-0-9\.]+),([-0-9\.]+)(?:,([-0-9\.]+))?(?:;u=([-0-9\.]+))?','i')::float[]
6251
$f$ LANGUAGE SQL IMMUTABLE;
6352
COMMENT ON FUNCTION str_geouri_decode(text)
6453
IS 'Decodes standard GeoURI of latitude and longitude into float array.'

0 commit comments

Comments
 (0)