[postgis-users] UPDATE a value using trigger and ST_Contains
Andy Colson
andy at squeakycode.net
Thu Feb 21 18:45:41 PST 2013
On 02/21/2013 06:37 PM, islanis at infomed.sld.cu wrote:
> Hello list, i have a doubt, i have 2 tables
> t1 and t2
> and t1 has many t2, that's the constraint, but i need a trigger that update the value of the FK on the t2 table
> cause i need to put the t1.gid on t2.munic_id automaticly when i update and insert, and i make this:
>
>
> BEGIN
>
> IF ST_Contains(t1.the_geom,ST_Centroid(NEW.the_geom)) = TRUE THEN
> NEW."munic_id" = t1.gid;
> END IF;
>
> RETURN NEW;
>
> END;
>
> and i get this error
>
>
> ERROR: falta una entrada para la tabla <<t1>> en la clausula FROM
>
> please what it means??, i need help
>
> ----------------------------------------------------------------
I'll make a guess. You need to write it as a select statement:
begin
select t1.gid from t1 where ST_Contains(t1.the_geom,ST_Centroid(NEW.the_geom)) info NEW."munic_id";
return NEW;
end;
Or something like that.
-Andy
More information about the postgis-users
mailing list