簡體   English   中英

下面是我遇到語法錯誤的 psql 代碼。 我正在嘗試在我的 test_route 數據庫上創建觸發器 function

[英]Below is the psql code in which I am having syntax error. I am trying to create a trigger function on my test_route database

CREATE OR REPLACE FUNCTION nearest_segment_insert()
RETURNS trigger AS
DECLARE id_temp integer;
$BODY$
BEGIN
    IF OLD.id = NULL THEN
         select test_route.id into id_temp,ST_Distance(test_route.the_geom,NEW.the_geom)
         FROM test_route,
         ORDER BY 2 ASC LIMIT 1;

         UPDATE SET p.edges_id = r.id, p.the_geom = r.the_geom, p.dist_val = r.distance, r.distance = -1 
         FROM test_route r, road_block p,
         WHERE id_temp = r.id ;
    END IF;

    RETURN NEW;
END;
$BODY$

我在“BEGIN”處或附近收到錯誤“語法錯誤”。

您收到的錯誤是因為:

CREATE OR REPLACE FUNCTION nearest_segment_insert()
RETURNS trigger AS
DECLARE id_temp integer;
$BODY$
...

應該:

CREATE OR REPLACE FUNCTION nearest_segment_insert()
RETURNS trigger
LANGUAGE plpgsql
AS
$BODY$
DECLARE id_temp integer;
...

有關更多信息,請參閱:

https://www.postgresql.org/docs/current/plpgsql-structure.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM