无法从命令行执行脚本

时间:2015-08-12 07:07:37

标签: postgresql plpgsql

我有PL / pgSQL函数定义需要在创建新数据的过程中从文件脚本运行。但是我在使用psql.exe和文件中的函数时遇到错误,但是在pgAdminIII中的SQL编辑器中运行它是完全正常的。问题是什么?还有其他运行PL / pgSQL脚本的简单解决方案吗?

这是错误消息:

  

psql:./../ Generic_SQL / db-create-functions-generic.sql:17:错误:   语法错误a t或接近“创建”第1行:创建或替换   功能pk_get(tabname character varyi ...

命令行是:

C:\"Program Files"\PostgreSQL\9.4\bin\psql -d OR -U postgres -f ".\..\Generic_SQL\db-create-lic-tables.sql"

实际文件内容为:

CREATE OR REPLACE FUNCTION pk_get(tabname character varying)
  RETURNS integer AS
$BODY$
DECLARE
    ThePK integer;
BEGIN

    --XStr:=TabName || HospUnitID; 
    --EXECUTE 'SELECT nextval(''' ||TabName || HospUnitID|| '''::regclass)' INTO ThePK; -- '' for the key name needed, so to escape needs dbl + general (so triple)
    --ThePK:=HospUnitID*100000 + ThePK+1;
    EXECUTE 'SELECT nextval(''' ||TabName || '_seq''::regclass)' INTO ThePK; -- '' for the key name needed, so to escape needs dbl + general (so triple)

    RETURN ThePK;

END;
$BODY$
  LANGUAGE plpgsql VOLATILE COST 100;    -- This is the line 17 that's apparently problematic
ALTER FUNCTION pk_get(character varying)
  OWNER TO postgres;

0 个答案:

没有答案
相关问题