需要帮助-创建触发器以更新列

时间:2018-10-17 17:21:15

标签: sql sql-update postgresql-9.4 postgresql-9.2 postgresql-9.5

尝试创建触发函数以更新点图层中的列,以更新具有来自另一点的ID的列。 第一层-设备安装在杆上(第二层)。在添加新设备时只想填写有关杆的信息。

尝试了以下代码:(我在历史记录备份中使用了类似的代码)

-1。在几何列中创建索引:

eg_data <- data.frame(addr1 = c('123 Main St','742 Evergreen 
Ter','8435 Roanoke Dr','1340 N State Pkwy') , addr2 = c('123 
Main St Apt 4','742 Evergreen Terrace','8435 Roanoke Dr Unit 
5','1340 N State Pkwy'), stringsAsFactors = FALSE)

eg_data$addr_comp2_1 <- mapply(vsetdiff, strsplit(eg_data$addr2,split=""), strsplit(eg_data$addr1, split=""))

eg_data$addr_comp2_2 = lapply(eg_data$addr_comp2_1, paste, collapse = '')

-2。功能:

CREATE INDEX idx_sc_48_lom_ar5_geom ON mapinfo.public.sc_48_lom_ar5 USING GIST("SP_GEOMETRY");

-3。创建触发器:

    CREATE OR REPLACE FUNCTION mapinfo.public.sc_48_lom_ar5_tracker() RETURNS trigger AS $sc_48_lom_ar5_tracker$
        BEGIN
            -- INSERT
            IF (TG_OP = 'INSERT') THEN
    SELECT ST_Buffer("SP_GEOMETRY",5, 'quad_segs=8') FROM mapinfo.public.poles_lom_ar5;
    UPDATE mapinfo.public.sc_48_lom_ar5 
    SET "Location_ID" = poles_lom_ar5."Location_ID"
    FROM mapinfo.public.poles_lom_ar5
    WHERE  ST_Contains (mapinfo.public.sc_48_lom_ar5."SP_GEOMETRY", mapinfo.public.poles_lom_ar5."SP_GEOMETRY");
                RETURN NEW;
            -- UPDATE
            ELSIF (TG_OP = 'UPDATE') THEN
    SELECT ST_Buffer("SP_GEOMETRY",5, 'quad_segs=8') FROM mapinfo.public.poles_lom_ar5;
    UPDATE mapinfo.public.sc_48_lom_ar5 
    SET "Location_ID" = poles_lom_ar5."Location_ID"
    FROM mapinfo.public.poles_lom_ar5
    WHERE  ST_Contains (mapinfo.public.sc_48_lom_ar5."SP_GEOMETRY", mapinfo.public.poles_lom_ar5."SP_GEOMETRY");
                RETURN NEW;
            END IF;
        END;
    $sc_48_lom_ar5_tracker$ LANGUAGE plpgsql;

SQL应用没有错误,但是当我尝试保存编辑内容时,我收到错误消息:

  

ODBC错误:ODBC RC = -1,ODBC SQLState = 42601,DBMS RC = 1,
  DBMS Msg = ERROR:查询没有结果数据的目标;
  执行查询时出错。操作已取消。

0 个答案:

没有答案