我为Postgres编写了以下函数,当通过pgAdmin安装时,它可以在我的本地Windows机器上正常工作。当我尝试将它添加到我的基于Linux的服务器安装时,它会抛出编译错误:
QUERY:SELECT $ 1(split_part($ 2,'',$ 3)) 语境:PL / PgSQL函数中的SQL语句“第23行附近的分裂词”
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;
有谷歌和文档的拖网,但我找不到任何相关的东西。我很迷茫!您可以提供的任何帮助都非常感谢!
答案 0 :(得分:2)
没有读取您的函数,但错误消息通常意味着变量与列的名称相同。使用_
前缀变量名通常是避免消息的好方法,它使plpgsql函数更具可读性。
此外,代码中至少出现一次=
,看起来应该是:=
。 plpgsql对这些东西很宽容,但你不应该依赖它。