Creé una función de activación. Cuando inserto una fila en la tabla. me sale un error Geom, k1k, k20k y pro_clustur_id están vacíos por defecto. Cuando se inserta una fila, se dispara el gatillo. ¿Como puedó resolver esté problema?
No se pudo ejecutar SQL. Error: ERROR: la función st_point(doble precisión, doble precisión) no existe LÍNEA 1: ...denem_project set geom = st_transform(st_setsrid(st_point(p... ^ SUGERENCIA: ninguna función coincide con el nombre dado y los tipos de argumentos. Usted es posible que deba agregar conversiones de tipos explícitos.CONSULTA: actualice denem.denem_project set geom = st_transform(st_setsrid(st_point(project_lng, project_lat), 4326), 500000) donde id no es nulo y pro_cluster_id es nulo y project_lng no es nulo y project_lat es no es nulo CONTEXTO: función PL/pgSQL create_cluster_id() línea 4 en declaración SQL
CREATE OR REPLACE FUNCTION denem.create_cluster_id() RETURNS trigger AS $$ BEGIN IF TG_OP = 'INSERT' THEN update denem.denem_project set geom = st_transform(st_setsrid(st_point(project_lng, project_lat), 4326), 500000) where id is not null and pro_cluster_id is null and project_lng is not null and project_lat is not null ; update denem.denem_project t1 set k20k=t2.fish_id from spatial.fish_net_k20k t2 where id is not null and pro_cluster_id is null and st_intersects(t1.geom,t2.geom) and k20k is null ; update denem.denem_project t1 set k1k=t2.fish_id from spatial.fish_net_k1k t2 where id is not null and pro_cluster_id is null and st_intersects(t1.geom,t2.geom) and k1k is null ; update denem.denem_project set pro_cluster_id= (id||''||k20k)::bigint where id is not null and pro_cluster_id is null and k20k is not null; END IF; RETURN NEW; END; $$ language 'plpgsql'; CREATE TRIGGER create_cluster_id AFTER INSERT ON denem.denem_project FOR EACH ROW EXECUTE PROCEDURE denem.create_cluster_id();Primero, averigüe en qué esquema está instalado PostGIS.
Puedes hacer esto en psql con
\dx postgiso con la consulta SQL
SELECT n.nspname FROM pg_extension x JOIN pg_namespace n ON x.extnamespace = n.oid WHERE x.extname = 'postgis';Una vez que sepa el nombre del esquema, cree la función de activación con
CREATE FUNCTION ... RETURNS trigger SET search_path='schemaname' AS ...;