Postgresql PL/PgSQL混淆错误
我已经为Postgres编写了以下函数,当通过pgAdmin安装时,它在我的本地windows计算机上运行良好。当我尝试将其添加到基于linux的服务器安装时,会抛出编译错误: 查询:选择$1拆分\u部分$2',,$3 上下文:PL/PgSQL函数中的SQL语句在第34行附近拆分字Postgresql PL/PgSQL混淆错误,postgresql,plpgsql,Postgresql,Plpgsql,我已经为Postgres编写了以下函数,当通过pgAdmin安装时,它在我的本地windows计算机上运行良好。当我尝试将其添加到基于linux的服务器安装时,会抛出编译错误: 查询:选择$1拆分\u部分$2',,$3 上下文:PL/PgSQL函数中的SQL语句在第34行附近拆分字 我浏览了谷歌和文档,但找不到任何相关的东西。我很困惑!非常感谢您提供的任何帮助 尚未读取函数,但错误消息通常表示变量与列具有相同的名称。用u作为变量名的前缀通常是避免该消息的一种好方法,它使plpgsql函数更具可读
我浏览了谷歌和文档,但找不到任何相关的东西。我很困惑!非常感谢您提供的任何帮助 尚未读取函数,但错误消息通常表示变量与列具有相同的名称。用u作为变量名的前缀通常是避免该消息的一种好方法,它使plpgsql函数更具可读性
此外,代码中至少出现了一个=,看起来应该是a:=。plpgsql原谅了这一点,但你不应该指望它。第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;