I'm sorry - I only speak/read english but I think I know what you are trying to do.<br><br>My table "tiles" is the same as your table t1 - a table of polygons.<br>My table "temp" is the same as your table t2 - a table of points.<br>
Both tables have a field "rec" where the tile table has the unique rec i want in the point table.<br><br>The following will first generate a geometry from the temp X and Y fields. Then it will populate the correct rec value from the tile table.<br>
<br>------------------------------------------------------------------------------------------------------------<br>-- Trigger: make_geom_trigger on public.temp<br><br>-- DROP TRIGGER make_geom_trigger ON public.temp;<br>
<br>CREATE TRIGGER make_geom_trigger<br> BEFORE INSERT<br> ON public.temp<br> FOR EACH ROW<br> EXECUTE PROCEDURE public.make_geom();<br><br>------------------------------------------------------------------------------------------------------------<br>
<br>-- Function: public.make_geom()<br><br>-- DROP FUNCTION public.make_geom();<br><br>CREATE OR REPLACE FUNCTION public.make_geom()<br> RETURNS trigger AS<br>$BODY$<br>BEGIN<br><br> NEW.the_geom = ST_SetSRID(ST_Point( NEW.x, NEW.y),2229);<br>
NEW.rec = (select rec from tiles t where st_intersects(NEW.the_geom,t.the_geom) limit 1);<br><br>return NEW;<br><br>END<br>$BODY$<br> LANGUAGE plpgsql VOLATILE<br> COST 100;<br>ALTER FUNCTION public.make_geom()<br> OWNER TO postgres;<br>
------------------------------------------------------------------------------------------------------------<br><br>Sorry if this doesn't follow the thread. Not sure I am doing this right.<br>Bruce<br>