![](/img/trans.png)
[英]I am having issues with a syntax error in PostgreSQL. I am trying to add a query and it is giving me an error
[英]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.