我试图用Postgresql使用一个函数来保存一些数据。这是创建脚本:
原文链接:https://www.f2er.com/postgresql/193121.html-- 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