考虑以下脚本:
create function login_web_user
(
p_email_address app_user.email_address%type,
p_password text
)
returns app_user_session.session_token%type as $$
declare
v_app_user_id app_user.id%type;
v_session_token app_user_session.session_token%type;
begin
select id
into v_app_user_id
from current_app_user
where email_address = p_email_address
and password_digest = crypt(p_password, password_digest);
if not found then
raise exception sqlstate 'SM001';
end if;
insert into app_user_session
(
app_user_id
)
values
(
v_app_user_id
)
returning session_token into v_session_token;
return v_session_token;
end;
$$ language plpgsql;
create function ws_login_web_user(jsonb) returns json as $$
select json_build_object
(
'sessionToken',
login_web_user
(
p_email_address := $1->>'emailAddress',
p_password := $1->>'password'
)
)
$$ language sql security definer;
grant execute on function ws_login_web_user(jsonb) to myapp_api;
当我通过pgAdmin3(以myapp_api
登录)
select ws_login_web_user
(
json_build_object
(
'emailAddress', 'foo@bar',
'password', 'demo'
)::jsonb
)
它运行没有错误。但是,当我通过JDBC执行完全相同的存储过程时,也以myapp_api
身份登录,我得到了这个:
ERROR: function crypt(text, text) does not exist
Hint: No function matches the given name and argument types. You might need to add explicit type casts.
Where: PL/pgSQL function login_web_user(character varying,character varying,text) line 7 at SQL statement
SQL function "ws_login_web_user" statement 1
我还重复了JDBC测试,这次登录为拥有上述对象的myapp
。我收到了完全相同的错误。
我正在使用PostgreSQL 9.4,9.4 JDBC驱动程序和Java 8。