· 8 years ago · Feb 07, 2018, 07:38 PM
1psql -h localhost -U myUser -f cobertura.sql myDB
2
3psql:cobertura.sql:29: ERROR: "sql " is not a known variable
4LINE 14: sql := format('insert into cobertura_tmp select count(*) as ...
5
6DO language plpgsql $$
7declare
8 eq record;
9 sql varchar;
10BEGIN
11
12create table if not exists cobertura_tmp (num integer, realtime char(1), lat numeric, lng numeric);
13
14truncate table cobertura_tmp;
15for eq in select imei_equipo as imei from cliente_avl_equipo where id_cliente in (select id from cliente where nombre ilike '%enangab%') limit 3
16
17loop
18
19sql := format('insert into cobertura_tmp select count(*) as num, tipo as realtime, round(CAST(latitud as numeric), 4) as lat ,round(CAST(longitud as numeric), 4) as lng from reports.avl_historico_%s where latitud between -38.67405472 and -36.75131149 and longitud between -73.08429161 and -69.65333954 group by tipo, round(CAST(latitud as numeric), 4),round(CAST(longitud as numeric), 4)', eq.imei);
20
21execute sql;
22
23end loop;
24
25update cobertura_tmp set num= -1* num where realtime='S';
26
27create table if not exists cobertura_tmp_resumen (num integer, lat numeric, lng numeric);
28truncate cobertura_tmp_resumen;
29
30END;
31$$;