我在PostGIS 1.5中使用PostgreSQL 9.1。在PostgreSQL 9.1中創建觸發器時的異常
我試圖讓這個觸發功能的終端工作(Ubuntu的):
CREATE FUNCTION insert_trigger()
RETURNS trigger AS
$insert_trigger$
BEGIN
IF (NEW.id >= 10 AND NEW.id < 100) THEN
INSERT INTO part_id_p10 VALUES (NEW.*);
ELSIF (NEW.id >= 100 AND NEW.id < 200) THEN
INSERT INTO part_id_p20 VALUES (NEW.*);
ELSE
RAISE EXCEPTION 'id out of range. Something wrong with the insert_trigger() function!';
END IF;
RETURN NULL;
END
$insert_trigger$ LANGUAGE plpgsql;
我得到這個異常:
SQLException: ERROR: Encountered "FUNCTION" at line 1, column 8.
SQLException: ERROR: Encountered "ELSIF" at line 1, column 1.
SQLException: ERROR: Encountered "ELSE" at line 1, column 1.
SQLException: Cannot commit when autoCommit is enabled.
SQLException: ERROR: Encountered "RETURN" at line 1, column 1.
SQLException: Cannot commit when autoCommit is enabled.
作品。也許你的文件中有BOM。你使用過哪個編輯器?在Linux終端中使用 – wildplasser
。實際上我正在開發一個羣集數據庫系統stado。除了這個函數,所有的sql命令都能正常工作。 – Shadin
'hexdump -c myfile.sql |頭「來查看文件開頭是否有奇怪的字符。 – wildplasser