Re: Ayuda con inquietud

From: Mario Sileone <msileone(at)gmail(dot)com>
To: pgsql-es-ayuda(at)postgresql(dot)org
Subject: Re: Ayuda con inquietud
Date: 2012-07-09 16:04:41
Message-ID: 4FFB0119.4050805@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

Te comento de mi experiencia, que si trabajas con reportes de GPS,
chequees la fecha sea igual o mayor a la anterior que tienes en la tabla
de ultimos reportes. Algunos equipos pueden disparar reportes retrasados
(no se si es tu caso) y hacer updates de fecha y hora de reportes
anteriores a la última.
Sobre todo IGUAL o mayor, ya que cualquier otro cambio que quieras hacer
sin tocar la fecha (Cambio de estado o lo que fuere) no te dejará.

Saludos

El 09/07/2012 12:56, Lazáro Rubén García Martínez escribió:
> Puedes hecharle un ojo a estos vínculos:
>
> http://www.postgresql.org.es/node/301
>
> http://www.postgresql.org.es/node/297
>
> Saludos.
> ________________________________________
> From: Jorge Toro [jolthgs(at)gmail(dot)com]
> Sent: Monday, July 09, 2012 10:59 AM
> To: Lazáro Rubén García Martínez
> Cc: Foro Postgres
> Subject: Re: [pgsql-es-ayuda] Ayuda con inquietud
>
> Hola Lazáro, En realidad te agradezco muchísimo tu ayuda.
>
> Yo estaba pensando en hacer algo como eso, en este momento estoy estudiando tu código.
> Mi idea era crear una función que cuando fuera llamada realizara un INSERT en la tabla "h_positions" y un UPDATE en una tabla como "positions".
>
> El problema son mis cortos conocimientos en temas como funciones, PL/pgSQL y triggres, me sería de gran ayuda no solo quedarme con tu solución, si no que si tienes documentación para novatos como yo, me puedas ayudar para aprender un poco sobre este tema.
>
> De antemano muchas gracias.
>
> Jorge Alonso Toro
> Ing. Teleinformático.
>
> http://jolthgs.wordpress.com/
> www.devmicrosystem.com<http://www.devmicrosystem.com>
> --------------------------------------------------------------
> Powered By Debian.
> Developer Bullix GNU/Linux.
> --------------------------------------------------------------
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.6 (GNU/Linux)
>
> iD8DBQBIWWH6q7mzdgTzI5ARAkX5AJ9TR6hL2ocLMOUDRfhts8DlVl+jpwCeNw5x
> p4+4FNUHPDUx1lU9F8WSKCA=
> =zRhQ
> -----END PGP SIGNATURE-----
> Este correo esta protegido bajo los términos de la Licencia Atribución-Compartir Obras Derivadas Igual a 2.5 Colombia de Creative Commons. Observé la licencia visitando este sitio http://creativecommons.org/licenses/by-sa/2.5/co/.
>
>
> El 9 de julio de 2012 10:21, Lazáro Rubén García Martínez <lgarciam(at)vnz(dot)uci(dot)cu<mailto:lgarciam(at)vnz(dot)uci(dot)cu>> escribió:
> Entonces podrias tener dos tablas positions, una que se llame hist_positions por ejemplo, y la otra positions, sobre positions almacenas la última ubicación de los gps y sobre hist_positions el historial de posiciones de los gps, para almacenar las posiciones de los gps utililizas una función, y para llevar el historial de los gps, puedes utilizar un trigger sobre positions. Acá te dejo el código de todo, solo falta la referencia de la clave foránea. Espero que te sirva.
>
> PD: Pudieran existir otras soluciones.
>
> --Crear la tabla positions
> CREATE TABLE public.positions (
> id SERIAL,
> gps_id INTEGER,
> posicion VARCHAR,
> velocidad REAL,
> altura REAL,
> fecha TIMESTAMP WITHOUT TIME ZONE,
> grados REAL,
> satelites INTEGER,
> CONSTRAINT positions_pkey PRIMARY KEY(id)
> ) WITHOUT OIDS;
>
> --Crear la tabla hist_positions
> CREATE TABLE public.hist_positions (
> id SERIAL,
> gps_id INTEGER,
> posicion VARCHAR,
> velocidad REAL,
> altura REAL,
> fecha TIMESTAMP WITHOUT TIME ZONE,
> grados REAL,
> satelites INTEGER,
> CONSTRAINT hist_positions_pkey PRIMARY KEY(id)
> ) WITHOUT OIDS;
>
> --Función para guardar en positions
> CREATE OR REPLACE FUNCTION public.fun_guardar_posicion (
> gps_id_ integer,
> posicion_ varchar,
> velocidad_ real,
> altura_ real,
> fecha_ timestamp,
> grados_ real,
> satelites_ integer
> )
> RETURNS integer AS
> $body$
> DECLARE
> retorno INTEGER;
> BEGIN
> UPDATE positions
> SET
> posicion = posicion_,
> velocidad = velocidad_,
> altura = altura_,
> fecha = fecha_,
> grados = grados_,
> satelites = satelites_
> WHERE gps_id = gps_id_
> RETURNING id INTO retorno;
>
> IF (retorno IS NULL) THEN
> INSERT INTO positions
> (
> gps_id,
> posicion,
> velocidad,
> altura,
> fecha,
> grados,
> satelites
> )
> VALUES (
> gps_id_,
> posicion_,
> velocidad_,
> altura_,
> fecha_,
> grados_,
> satelites_
> )RETURNING id INTO retorno;
> END IF;
>
> RETURN retorno;
> END;
> $body$
> LANGUAGE 'plpgsql';
>
> --Función ejecutada por el trigger para guardar en el historial de positions
> CREATE OR REPLACE FUNCTION public.fun_trg_hist_positions (
> )
> RETURNS trigger AS
> $body$
> DECLARE
> BEGIN
> INSERT INTO hist_positions
> (
> gps_id,
> posicion,
> velocidad,
> altura,
> fecha,
> grados,
> satelites
> )
> VALUES (
> NEW.gps_id,
> NEW.posicion,
> NEW.velocidad,
> NEW.altura,
> NEW.fecha,
> NEW.grados,
> NEW.satelites
> );
>
> RETURN NULL;
> END;
> $body$
> LANGUAGE 'plpgsql';
>
> --Trigger utilizado
> CREATE TRIGGER trg_hist_positions AFTER INSERT OR UPDATE
> ON public.positions FOR EACH ROW
> EXECUTE PROCEDURE public.fun_trg_hist_positions();
>
> Saludos a todos.
> ________________________________________
> From: pgsql-es-ayuda-owner(at)postgresql(dot)org<mailto:pgsql-es-ayuda-owner(at)postgresql(dot)org> [pgsql-es-ayuda-owner(at)postgresql(dot)org<mailto:pgsql-es-ayuda-owner(at)postgresql(dot)org>] On Behalf Of Jorge Toro [jolthgs(at)gmail(dot)com<mailto:jolthgs(at)gmail(dot)com>]
> Sent: Monday, July 09, 2012 9:43 AM
> To: Foro Postgres
> Subject: Re: [pgsql-es-ayuda] Ayuda con inquietud
>
> Hola Lazáro, gracias por responder.
>
> Sí gps.id<http://gps.id><http://gps.id> es la referencia a una tabla "gps" que se usa para registrar cada uno de los GPS que se registran para ser aceptados por el servidor.
> Esta tabla "gps" tiene datos como: id, name, type, active. de cada uno de los GPS. Y la tabla "position" se encarga de almacenar los reportes (históricos) hechos por cada GPS.
>
> Y lo que quiero lograr es, tener a la mano siempre que consulte un dispositivo, toda la última información de dicho dispositivo que se encuentre en la tabla "position".
>
> Pero no quiero realizar una consulta directa a la tabla "position" porque son alrededor de 1000 GPS reportando cada minuto y esta tabla "position" tenderá a ser demasiado grande con el pasar del tiempo.
>
>
> Por tu ayuda muchas gracias,
>
>
> Jorge Alonso Toro
> Ing. Teleinformático.
>
> http://jolthgs.wordpress.com/
> www.devmicrosystem.com<http://www.devmicrosystem.com><http://www.devmicrosystem.com>
> --------------------------------------------------------------
> Powered By Debian.
> Developer Bullix GNU/Linux.
> --------------------------------------------------------------
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.6 (GNU/Linux)
>
> iD8DBQBIWWH6q7mzdgTzI5ARAkX5AJ9TR6hL2ocLMOUDRfhts8DlVl+jpwCeNw5x
> p4+4FNUHPDUx1lU9F8WSKCA=
> =zRhQ
> -----END PGP SIGNATURE-----
> Este correo esta protegido bajo los términos de la Licencia Atribución-Compartir Obras Derivadas Igual a 2.5 Colombia de Creative Commons. Observé la licencia visitando este sitio http://creativecommons.org/licenses/by-sa/2.5/co/.
>
>
> El 9 de julio de 2012 09:17, Lazáro Rubén García Martínez <lgarciam(at)vnz(dot)uci(dot)cu<mailto:lgarciam(at)vnz(dot)uci(dot)cu><mailto:lgarciam(at)vnz(dot)uci(dot)cu<mailto:lgarciam(at)vnz(dot)uci(dot)cu>>> escribió:
> La columna gps_id es única
>
>
> ________________________________
> Fin a la injusticia, LIBERTAD AHORA A NUESTROS CINCO COMPATRIOTAS QUE SE ENCUENTRAN INJUSTAMENTE EN PRISIONES DE LOS EEUU!
> http://www.antiterroristas.cu
> http://justiciaparaloscinco.wordpress.com
>
> Fin a la injusticia, LIBERTAD AHORA A NUESTROS CINCO COMPATRIOTAS QUE SE ENCUENTRAN INJUSTAMENTE EN PRISIONES DE LOS EEUU!
> http://www.antiterroristas.cu
> http://justiciaparaloscinco.wordpress.com
>
>
> ________________________________
> Fin a la injusticia, LIBERTAD AHORA A NUESTROS CINCO COMPATRIOTAS QUE SE ENCUENTRAN INJUSTAMENTE EN PRISIONES DE LOS EEUU!
> http://www.antiterroristas.cu
> http://justiciaparaloscinco.wordpress.com
>
> Fin a la injusticia, LIBERTAD AHORA A NUESTROS CINCO COMPATRIOTAS QUE SE ENCUENTRAN INJUSTAMENTE EN PRISIONES DE LOS EEUU!
> http://www.antiterroristas.cu
> http://justiciaparaloscinco.wordpress.com
> -
> Enviado a la lista de correo pgsql-es-ayuda (pgsql-es-ayuda(at)postgresql(dot)org)
> Para cambiar tu suscripción:
> http://www.postgresql.org/mailpref/pgsql-es-ayuda
>

--
Mario Sileone

In response to

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message Alejandro Carrillo 2012-07-09 16:12:11 Re: Ayuda con inquietud
Previous Message Alvaro Hilario 2012-07-09 15:57:04 Re: instalar postgres 9.1 en kubuntu