Repository navigation
Expand file tree
/
Copy pathsicob_store_in_repository.sql
More file actions
66 lines (56 loc) · 1.95 KB
/
Copy pathsicob_store_in_repository.sql
File metadata and controls
66 lines (56 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
SET CLIENT_ENCODING TO 'utf8';
CREATE OR REPLACE FUNCTION public.sicob_store_in_repository(_opt json)
RETURNS json
LANGUAGE plpgsql
AS $function$
DECLARE
_out json := '{}';
-------------------------------
BEGIN
---------------------------
--PARAMETROS DE ENTRADA
---------------------------
--> lyr : capa de poligonos que se almacenara en el repositorio.
--> condition (opcional): Filtro para los datos de "lyr". Si no se especifica, se toman todos los registros.
--> repository : nombre de la tabla 'repositorio' donde se almacenaran los registros.
--> add (opcional true/false): Si exiten registros en repositorio con el valor de layerid igual al lyr,
--> no son eliminados.
---------------------------
--VALORES DEVUELTOS
---------------------------
--> row_cnt : Cantidad de registros insertados.
IF (COALESCE((_opt->>'add')::boolean,FALSE)) = FALSE THEN
EXECUTE 'DELETE FROM ' || (_opt->>'repository')::text ||
' WHERE layerid = ''' ||
(sicob_split_table_name((_opt->>'lyr')::text)).table_name || ''' OR ' ||
'layerid = ''' || ((_opt->>'lyr')::text) || '''';
END IF;
SELECT sicob_executesql('
INSERT INTO ' || (_opt->>'repository')::text || '(layerid, data, the_geom)
SELECT ''' || (sicob_split_table_name((_opt->>'lyr')::text)).table_name || ''' as layerid, data, the_geom from (
select
sicob_id,
(
select row_to_json(d)
from (
select ' ||
sicob_no_geo_column(
'' || (_opt->>'lyr')::text || '',
'{gid,sicob_utm,sicob_sup,topogeom}',
'd.'
) || '
from ' || (_opt->>'lyr')::text || ' d
where d.sicob_id=s.sicob_id
) d
) as data,
the_geom
from ' || (_opt->>'lyr')::text || ' s
) t','{}'::json) INTO _out;
RETURN _out;
/** FIN!!! **/
EXCEPTION
WHEN others THEN
RAISE EXCEPTION 'geoSICOB (sicob_store_in_repository) % , % , _opt: % ', SQLERRM, SQLSTATE, _opt;
END;
$function$