gpt4 book ai didi

postgresql - 如何调用一个函数,PostgreSQL

转载 作者:行者123 更新时间:2023-11-29 11:06:19 25 4
gpt4 key购买 nike

我正在尝试使用 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 语句。

最佳答案

函数调用仍然应该是一个有效的 SQL 语句:

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

关于postgresql - 如何调用一个函数,PostgreSQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1953326/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com