函数符号(json,未知)不存在
function sign(json, unknown) does not exist
我正在学习 https://postgrest.org/en/v5.0/auth.html#jwt-from-sql
上的教程
我创建了这个函数:
create or replace function
login(email text, pass text) returns basic_auth.jwt_token
language plpgsql
as $$
declare
_role name;
result basic_auth.jwt_token;
begin
-- check email and password
select basic_auth.user_role(email, pass) into _role;
if _role is null then
raise invalid_password using message = 'invalid user or password';
end if;
select sign(
row_to_json(r), 'reallyreallyreallyreallyverysafe'
) as token
from (
select _role as role, login.email as email,
extract(epoch from now())::integer + 60*60 as exp
) r
into result;
return result;
end;
$$;
当我尝试执行登录请求时,收到以下错误消息:
{
"hint": "No function matches the given name and argument types. You might need to add explicit type casts.",
"details": null,
"code": "42883",
"message": "function public.sign(json, unknown) does not exist" }
我在教程中的任何地方都没有看到符号函数,有人知道这里发生了什么吗?
签名功能是在安装时创建的pgjwt。
此外,请确保将扩展安装在包含在 search_path(导入模式列表)中的模式上。这可以通过执行 CREATE EXTENSION pgjwt WITH SCHEMA public
.
来指定
PostgREST 默认在 search_path
上添加 public
架构,因此扩展应该无需额外配置即可工作。
我正在学习 https://postgrest.org/en/v5.0/auth.html#jwt-from-sql
上的教程我创建了这个函数:
create or replace function
login(email text, pass text) returns basic_auth.jwt_token
language plpgsql
as $$
declare
_role name;
result basic_auth.jwt_token;
begin
-- check email and password
select basic_auth.user_role(email, pass) into _role;
if _role is null then
raise invalid_password using message = 'invalid user or password';
end if;
select sign(
row_to_json(r), 'reallyreallyreallyreallyverysafe'
) as token
from (
select _role as role, login.email as email,
extract(epoch from now())::integer + 60*60 as exp
) r
into result;
return result;
end;
$$;
当我尝试执行登录请求时,收到以下错误消息:
{ "hint": "No function matches the given name and argument types. You might need to add explicit type casts.", "details": null, "code": "42883", "message": "function public.sign(json, unknown) does not exist" }
我在教程中的任何地方都没有看到符号函数,有人知道这里发生了什么吗?
签名功能是在安装时创建的pgjwt。
此外,请确保将扩展安装在包含在 search_path(导入模式列表)中的模式上。这可以通过执行 CREATE EXTENSION pgjwt WITH SCHEMA public
.
PostgREST 默认在 search_path
上添加 public
架构,因此扩展应该无需额外配置即可工作。