Hello I want to create a trigger with plplythonu<br>that will take long and lat from columns "long" and "lat" and write/update into column "gis_pos" GeomFromText('POINT(long lat)') when "long" and/or "lat" are updated or inserted.<br>
<br>I thought it would be as simple as:<br><br>CREATE OR REPLACE FUNCTION update_gispos()<br>  RETURNS "trigger" AS<br>$BODY$<br>TD["new"]["gis_pos"] = GeomFromText('POINT(TD["new"]["long"] TD["new"]["lat"])')<br>
return "MODIFY"<br>$BODY$<br>  LANGUAGE 'plpythonu' VOLATILE;<br>ALTER FUNCTION update_gispos() OWNER TO pmartinez;<br><br>This raise the error global name GeomFromText is unknown.<br><br>FEHLER:  plpython: function "update_gispos" failed<br>
DETAIL:  exceptions.NameError: global name 'GeomFromText' is not defined<br><br><br>How can I make the function GeomFromText available within the Trigger function?<br><br>--<br>I also tried to parse long and lat with string formating:<br>
<br>CREATE OR REPLACE FUNCTION update_gispos()<br>  RETURNS "trigger" AS<br>$BODY$<br>TD["new"]["gis_pos"] = "GeomFromText('POINT(%s %s)')" %(TD["new"]["long"], TD["new"]["lat"])<br>
return "MODIFY"<br>$BODY$<br>  LANGUAGE 'plpythonu' VOLATILE;<br>ALTER FUNCTION update_gispos() OWNER TO pmartinez;<br><br><br>Which obviously raise an error, I guess because geometry cannot be a string:<br>
FEHLER:  parse error - invalid geometry<br><br>I would appreciate any help.<br><br>pedro<br>