如何调用函数PostgreSQL

前端之家收集整理的这篇文章主要介绍了如何调用函数PostgreSQL前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图用Postgresql使用一个函数来保存一些数据。这是创建脚本:
-- Function: "saveUser"(integer,character varying,character varying)

-- DROP FUNCTION "saveUser"(integer,character varying);

CREATE OR REPLACE FUNCTION "saveUser"("pUserID" integer,"pName" character varying,"pLastName" character varying,"pUserName" character varying,"pPassword" character varying,"peMail" character varying)
  RETURNS boolean AS
$BODY$
BEGIN
SELECT 1
FROM "USERS"
WHERE "userID" = $1;

IF FOUND THEN
UPDATE "USERS" 
    SET     "name" = $2,"lastName" = $3,"userName" = $4,"password" = $5,"eMail" = $6
WHERE "userID" = $1;
ELSE
    INSERT INTO "USERS"
    ("name","lastName","userName","password","eMail")
    VALUES
        ($2,$3,$4,$5,$6);
END IF;
END;$BODY$
  LANGUAGE 'plpgsql' VOLATILE
  COST 100;
ALTER FUNCTION "saveUser"(integer,character varying) OWNER TO postgres;

Postresql文档指出,要调用不返回任何结果集的函数,仅写入其名称属性就足够了。所以我尝试调用这样的功能

"saveUser"(3,'asd','asd');

但是我收到以下错误

ERROR:  Syntax error at or near ""saveUser""
LINE 1: "saveUser"(3,'asd')
     ^

********** Error **********

ERROR: Syntax error at or near ""saveUser""
sql state: 42601
Character: 1

我有其他功能返回结果集。我使用SELECT * FROM“fnc”(…)来调用它们,它可以工作。为什么我得到这个错误

编辑:我正在使用pgAdmin III查询工具,并试图在那里执行sql语句。

函数调用仍然应该是一个有效的sql语句:
SELECT "saveUser"(3,'asd');

猜你在找的Postgre SQL相关文章