【发布时间】:2015-07-05 11:02:11
【问题描述】:
我正在使用 Postgres 8.4,并尝试使用以下命令从命令行运行 create function ... 脚本
psql dbname -U username -f filename
或
psql -f filename -d dbname -U username
它总是会导致以下错误
psql:mergenodedata.sql:40:错误:“创建”处或附近的语法错误 第 1 行:创建或替换 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
【问题讨论】:
-
不相关的有趣事实:老实说,我现在唯一的愿望是让“传奇徽章”天数计数器切换......我忘记了:一旦你从 任何事情在某一天。而那个被删除的问题......仍然显示为 +40 ... -40 。所以这 4 次投票仍然有助于第 149 天。
标签: postgresql plpgsql