我在postgres中编写了一个基本的插入函数,目的是使用加密的密码插入数据,我使用了Postgres本机函数 PGP_SYS_ENCRYPT
,但遇到此错误:>
ERROR: function pgp_sym_encrypt(text, unknown) does not exist
LINE 3: PGP_SYM_ENCRYPT(pass,'AES_KEY'),'0')
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
QUERY: INSERT INTO users (username,email,password_,isDriver,login_status) VALUES(usn,
em,
PGP_SYM_ENCRYPT(pass,'AES_KEY'),'0')
CONTEXT: PL/pgSQL function create_users(character varying,character varying,text,character varying) line 5 at SQL statement
SQL state: 42883
我不知道为什么会这样,下面是我的功能,我缺少什么? :
CREATE OR REPLACE FUNCTION public.create_users(
usn character varying,
em character varying,
pass text,
isd character varying)
RETURNS integer
LANGUAGE 'plpgsql'
COST 100
VOLATILE
AS $BODY$
declare
total integer;
BEGIN
INSERT INTO users (username,email,password_,isDriver,login_status) VALUES(usn,
em,
PGP_SYM_ENCRYPT(pass,'AES_KEY'),'0');
RETURN 1;
END;
$BODY$;
ALTER FUNCTION public.create_users(character varying, character varying, text, character varying)
OWNER TO postgres;
答案 0 :(得分:1)
一个疯狂的猜测是:也许您没有安装?。
db=# \sf pgp_sym_encrypt
ERROR: function "pgp_sym_encrypt" does not exist
所以你只是
db=# create extension pgcrypto ;
CREATE EXTENSION
和:
db=# \sf pgp_sym_encrypt(text,text)
CREATE OR REPLACE FUNCTION public.pgp_sym_encrypt(text, text)
RETURNS bytea
LANGUAGE c
PARALLEL SAFE STRICT
AS '$libdir/pgcrypto', $function$pgp_sym_encrypt_text$function$