我正在尝试使用 PostgreSQL 的一个函数来保存一些数据,下面是创建脚本:
-- Function: "saveUser"(integer, character varying, character varying, character varying, character varying, character varying)
-- DROP FUNCTION "saveUser"(integer, character varying, character varying, character varying, character varying, 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, character varying, character varying, character varying, character varying) OWNER TO postgres;
PostreSQL 文档指出,要调用不返回任何结果集的函数,只需写入其名称和属性即可。所以我试着这样调用函数:
"saveUser"(3, 'asd','asd','asd','asd','asd');
但我得到了以下错误:
ERROR: syntax error at or near ""saveUser""
LINE 1: "saveUser"(3, 'asd','asd','asd','asd','asd')
^
********** Error **********
ERROR: syntax error at or near ""saveUser""
SQL state: 42601
Character: 1
我还有其他函数可以返回结果集。我用 SELECT * FROM "fnc"(...)
呼叫他们,它工作。为什么我会得到这个错误?
编辑: 我正在使用 pgAdmin III 查询工具并尝试在那里执行 SQL 语句。