2017-04-17 247 views
1

我创建了一个触发器函数。当我插入一行到表。我收到一个错误。 Geom,k1k,k20k和pro_clustur_id默认为空。当插入一行时触发器被触发。我怎么解决这个问题?Postgresql触发器执行错误

Failed to execute SQL. Error: ERROR: function st_point(double precision, double precision) does not exist LINE 1: ...denem_project set geom = st_transform(st_setsrid(st_point(p...^HINT: No function matches the given name and argument types. You might need to add explicit type casts. QUERY: 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 CONTEXT: PL/pgSQL function create_cluster_id() line 4 at SQL statement

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(); 
+0

PostGIS未安装,或安装在sch ema不在数据库用户的“search_path”中。 –

+0

已安装Postgis – Fatih

回答

0

首先,找出其中的模式安装PostGIS的。

您可以用

\dx postgis 

或SQL查询

SELECT n.nspname 
FROM pg_extension x 
    JOIN pg_namespace n 
     ON x.extnamespace = n.oid 
WHERE x.extname = 'postgis'; 

一旦你知道的模式名称,创建触发器功能与做在psql

CREATE FUNCTION ... RETURNS trigger SET search_path='schemaname' AS ...;