无法使用 psql -f 文件名选项创建 plpgsql 函数

Cannot create plpgsql function using psql -f filename option

我正在使用 Postgres 8.4,我尝试使用

从命令行运行一个create function ...脚本
psql dbname -U username -f filename

psql -f filename -d dbname -U username 

并且它总是导致以下错误

psql:mergenodedata.sql:40: ERROR: syntax error at or near "create" LINE 1: create or replace FUNCTION updNode (oldnodename varchar, ne...

第 40 行是文件的结尾

$$ LANGUAGE plpgsql;

如果我将文件的文件内容剪切并粘贴到 pgadmin 或打开的 psql 会话中,那么 create function 会很完美。

密码是

create or replace FUNCTION updNode (oldnodename varchar, newnodename varchar, scnname varchar, cid integer) returns void AS $$
declare
        oldnodeid integer;
        newnodeid integer;
        scnid integer;
        newcount integer;
        oldcount integer;

BEGIN

raise notice 'doing %', oldnodename;

select id from nodes where nodename = oldnodename and cityid = cid into oldnodeid;
select id from nodes where nodename = newnodename and cityid = cid into newnodeid;
select id from scenario where name = scnname and cityid = cid into scnid;

raise notice 'oldnodeid is %', oldnodeid;
raise notice 'newnodeid is %', newnodeid;
raise notice 'scnid is %', scnid;

select count(*) from collection_node_result where node1id = newnodeid and scenario_collection_id in (
        select id from scenario_collection where scenarioid = scnid into newcount
);

raise notice 'newcount is %', newcount;

select count(*) from collection_node_result where node1id = oldnodeid and scenario_collection_id in (
        select id from scenario_collection where scenarioid = scnid into oldcount
);

raise notice 'oldcount is %', oldcount;


update collection_node_result set node1id = newnodeid where node1id = oldnodeid and scenario_collection_id in (
        select id from scenario_collection where scenarioid = scnid
);


END;
$$ LANGUAGE plpgsql;

我参考的其他页面是

Run plpgsql program to update the data in table

http://www.postgresql.org/docs/8.4/static/plpgsql-development-tips.html

它看起来像损坏的文件 - 一些问题可以通过 BOM http://en.wikipedia.org/wiki/Byte_order_mark 或结尾符号“^z”强制执行。在某些 hexeditor 中查看文件并检查文件的开头和结尾。当我使用在其他操作系统上创建的文件时,我遇到了类似的问题。