[postgis-users] Trigger in plpythonu
Pedro Martinez Arbizu
pmartinez at senckenberg.de
Sun May 18 10:10:11 PDT 2008
Hello I want to create a trigger with plplythonu
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.
I thought it would be as simple as:
CREATE OR REPLACE FUNCTION update_gispos()
RETURNS "trigger" AS
$BODY$
TD["new"]["gis_pos"] = GeomFromText('POINT(TD["new"]["long"]
TD["new"]["lat"])')
return "MODIFY"
$BODY$
LANGUAGE 'plpythonu' VOLATILE;
ALTER FUNCTION update_gispos() OWNER TO pmartinez;
This raise the error global name GeomFromText is unknown.
FEHLER: plpython: function "update_gispos" failed
DETAIL: exceptions.NameError: global name 'GeomFromText' is not defined
How can I make the function GeomFromText available within the Trigger
function?
--
I also tried to parse long and lat with string formating:
CREATE OR REPLACE FUNCTION update_gispos()
RETURNS "trigger" AS
$BODY$
TD["new"]["gis_pos"] = "GeomFromText('POINT(%s %s)')" %(TD["new"]["long"],
TD["new"]["lat"])
return "MODIFY"
$BODY$
LANGUAGE 'plpythonu' VOLATILE;
ALTER FUNCTION update_gispos() OWNER TO pmartinez;
Which obviously raise an error, I guess because geometry cannot be a string:
FEHLER: parse error - invalid geometry
I would appreciate any help.
pedro
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20080518/7211f6b9/attachment.html>
More information about the postgis-users
mailing list