Postgresql触发器执行错误

时间:2017-04-17 12:29:57

标签: postgresql

我创建了一个触发器功能。当我向表中插入一行时。我收到一个错误。 Geom,k1k,k20k和pro_clustur_id默认为空。插入行时会触发触发器。我该如何解决这个问题?

  

无法执行SQL。错误:错误:函数st_point(双精度,双精度)不存在第1行:... denem_project set geom = st_transform(st_setsrid(st_point(p ... ^ HINT:没有函数匹配给定的名称和参数类型。你。可能需要添加显式类型转换.QUERY:update denem.denem_project set geom = st_transform(st_setsrid(st_point(project_lng,project_lat),4326),500000)其中id不为null且pro_cluster_id为null且project_lng不为null且project_lat为not null语境:PL / pgSQL函数create_cluster_id()SQL语句中的第4行

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

1 个答案:

答案 0 :(得分:0)

首先,找出安装PostGIS的架构。

您可以使用

psql中执行此操作
\dx postgis

或使用SQL查询

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

了解架构名称后,使用

创建触发器功能

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