【发布时间】:2011-05-12 10:49:58
【问题描述】:
我为 Postgres 编写了以下函数,当通过 pgAdmin 安装时,它在我的本地 Windows 机器上运行良好。当我尝试将它添加到基于 linux 的服务器安装时,它会引发编译错误:
查询:选择 $1 (split_part($2,'', $3)) 上下文:第 34 行附近的 PL/PgSQL 函数“splitwords”中的 SQL 语句
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;
搜索了谷歌和文档,但我找不到任何相关内容。我很困扰!非常感谢您提供的任何帮助!
【问题讨论】:
标签: postgresql plpgsql