【问题标题】:Postgresql Trigger execute errorPostgresql 触发器执行错误
【发布时间】:2017-09-13 01:46:05
【问题描述】:

我创建了一个触发函数。当我在表格中插入一行时。我得到一个错误。 Geom、k1k、k20k 和 pro_clustur_id 默认为空。当插入一行时触发触发器。我该如何解决这个问题?

执行 SQL 失败。错误:错误:函数 st_point(双精度,双精度)不存在第 1 行:...denem_project set geom = st_transform(st_setsrid(st_point(p... ^ 提示:没有函数匹配给定的名称和参数类型。你可能需要添加显式类型转换。查询:更新 denem.denem_project set geom = st_transform(st_setsrid(st_point(project_lng, project_lat), 4326), 500000) 其中 id 不为空,pro_cluster_id 为空,project_lng 不为空,project_lat 为不为空 CONTEXT: PL/pgSQL 函数 create_cluster_id() 第 4 行的 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();

【问题讨论】:

  • 要么没有安装PostGIS,要么安装在数据库用户search_path之外的架构中。
  • Postgis 已安装

标签: postgresql


【解决方案1】:

首先,找出 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 <strong>SET search_path='schemaname'</strong> AS ...;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-05
    • 2012-09-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多