2011-05-12 81 views
0

我已經爲Postgres編寫了以下函數,並且在通過pgAdmin安裝時,它可以在本地Windows機器上正常工作。當我嘗試將其添加到我的基於Linux的服務器安裝它拋出編譯錯誤:PL/PgSQL令人困惑的錯誤

查詢:SELECT $ 1(split_part($ 2,」」,$ 3)) 背景:在PL/pgSQL函數 「splitwords」 SQL語句近線34

CREATE OR REPLACE FUNCTION splitwords(text, int) 
    RETURNS text AS 
$BODY$ 
DECLARE 
inwords ALIAS FOR $1; 
posn INTEGER; 
existcount INTEGER; 
incurrdataid ALIAS FOR $2; 
currdataid INTEGER; 
currwordid INTEGER; 
length INTEGER; 
wordpos INTEGER; 
newword TEXT; 
BEGIN 
currdataid:=incurrdataid; 
currdataid:=currdataid-1; --corrects for auto-increment error 
posn:=1; 
WHILE posn<11 LOOP 
IF split_part(inwords,' ',posn)='' THEN 
-- If no more words are available 
    EXIT; 
ELSE 
--If not at the end of the words 
    IF (SELECT wordID FROM words WHERE word=split_part(inwords,' ',posn))>0 THEN 
    --If word is already in lexicon 
     currwordid:=(SELECT wordID FROM words WHERE word=split_part(inwords,' ',posn))::INTEGER; 
     existcount:= (SELECT count FROM words WHERE word=split_part(inwords,' ',posn))::INTEGER; 
     UPDATE words SET count=existcount+1 WHERE word=split_part(inwords,' ',posn); 
     INSERT INTO wordsdata(wordid,dataid) VALUES (currwordid,currdataid); 
     posn:=posn+1; 
    ELSE 
    --If word is new 
     newword=split_part(inwords,' ',posn); 
     INSERT INTO words(word,count) VALUES (newword,1); 
     currwordid:=(SELECT wordID FROM words WHERE word=split_part(inwords,' ',posn))::INTEGER; 
     INSERT INTO wordsdata(wordid,dataid) VALUES (currwordid,currdataid); 
     length:=length(split_part(inwords,' ',posn)); 
     wordpos:=1; 
     WHILE wordpos<(length+1) LOOP 
      INSERT INTO searchchar(searchstr,wordid) VALUES (substring(split_part(inwords,' ',posn),1,wordpos),currwordid); 
      wordpos=wordpos+1; 
     END LOOP; 
     posn:=posn+1; 
    END IF; 
END IF; 
END LOOP; 

RETURN 'rows added'; 
END 
$BODY$ 
    LANGUAGE plpgsql VOLATILE 
    COST 100; 

當初谷歌的拖網和文檔,但我無法找到任何有關。我很困擾!任何幫助你可能會提供非常感謝!

回答

2

沒有讀取您的函數,但錯誤消息通常表示變量與列具有相同的名稱。使用_前綴變量名通常是避免消息的好方法,並且它使plpgsql函數更具可讀性。

此外,您的代碼中至少有一次出現=,看起來應該是:=。 plpgsql是原諒這個東西,但你不應該指望它。

+3

第34行有保留字「count」。這將是我的第一個猜測。 – Mel 2011-05-12 14:39:09