gpt4 book ai didi

sql - plpgsql 错误 : syntax error at or near ":"

转载 作者:行者123 更新时间:2023-11-29 13:43:50 24 4
gpt4 key购买 nike

我收到标题中的错误。对我来说奇怪的是我的 SQL 代码中没有任何冒号。

CREATE OR REPLACE FUNCTION "CreateUser" (
"@first_name" VARCHAR(25),
"@last_name" VARCHAR(25),
"@email" VARCHAR(254),
"@password" VARCHAR(250)
)
RETURNS UUID AS
$func$
DECLARE "id" UUID;
BEGIN
"id" = uuid_generate_v4();
INSERT INTO
"users" (
"id",
"first_name",
"last_name",
"email",
"password"
)
VALUES (
"id",
"@first_name",
"@last_name",
"@email",
"@password"
);
RETURN "id";
END;
$func$ LANGUAGE PLPGSQL;

字段类型都是一样的,所以不可能是类型问题。

是否某处缺少分号,或者这只是结构不正确?

最佳答案

事实证明,我没有在 sql 上设置包 uuid_generate_v4(); 并且不确定如何支持它,所以至少暂时,我在服务器上创建了一个 uuid 并且将其传递到 sql 中。

CREATE OR REPLACE FUNCTION "CreateUser" (
"@newid" UUID,
"@first_name" VARCHAR(25),
"@last_name" VARCHAR(25),
"@email" VARCHAR(254),
"@password" VARCHAR(250)
)
RETURNS UUID AS
$func$
DECLARE "id" UUID;
BEGIN
INSERT INTO
"users" (
"id",
"first_name",
"last_name",
"email",
"password"
)
VALUES (
"@newid",
"@first_name",
"@last_name",
"@email",
"@password"
);
RETURN "id";
END;
$func$ LANGUAGE PLPGSQL;

关于sql - plpgsql 错误 : syntax error at or near ":",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51545338/

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