[postgis-users] GeometryFromText Problem

strk at refractions.net strk at refractions.net
Thu Dec 9 14:11:14 PST 2004


On Thu, Dec 09, 2004 at 06:31:50PM -0200, Gustavo Oliveira wrote:
> Hi all!
> 
> I am trying to do a function that tranform some data into a geometry and
> update a table.
> 
> It seems like that:
> 
> CREATE OR REPLACE FUNCTION atualiza_posicao()
>   RETURNS trigger AS
> '
>   BEGIN
> 
> 	IF NEW.idviatura IS NULL THEN
>             RAISE EXCEPTION \'Campo viatura nao pode ser nulo\';
>         END IF;
> 
> 	IF NEW.datahora IS NULL THEN
>             RAISE EXCEPTION \'Viatura % sem timestamp\', NEW.idviatura;
>         END IF;
> 
> 	UPDATE historico_viatura 
> 		SET 
> 			localizacaoutm = select
> transform(geometryfromtext(\'POINT(-NEW.latitude
> -NEW.longitude)\',4326),40000)

SELECT ... INTO localizacaoutm
Something similar.
Check (lw)postgis.sql for that pattern.
--strk;

> 		WHERE
> 			idhistorico = NEW.idhistorico;
> 
> 	UPDATE posicao_viatura
> 		SET 
> 		    localizacaoutm =  select
> transform(geometryfromtext(\'POINT(-NEW.latitude
> -NEW.longitude)\',4326),40000),
> 		    datahora = NEW.datahora,
> 		    velocidade = NEW.velocidade * 1.852 
> 		WHERE
> 		    idviatura = NEW.idviatura;
>     
>     RETURN NEW;
>   END;
> '
>   LANGUAGE 'plpgsql' VOLATILE;
> 
> I had a problem when I try to execute it... The error follows here:
> 
> new_ae=#  INSERT INTO historico_viatura (idhistorico, idviatura, latitude,
> latitudep, longitude, longitudep, velocidade, datahora)  VALUES
> (nextval('seq_historico'), 38103, 47, 'S', 22, 'W', 45, now());
> ERROR:  syntax error at or near "select" at character 9
> CONTEXT:  PL/pgSQL function "sp_atualiza_posicao" line 12 at assignment
> 
> Does someone could help me?
> 
> Thanks a lot!
> 
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users



More information about the postgis-users mailing list