触发器内部不存在postgresql扩展函数

问题描述 投票:0回答:1

我已使用

CREATE EXTENSION pgsodium
将 pgsodium 安装到数据库中。 这是 \dx

的输出
citext   | 1.6     | public  
pgsodium | 3.1.9   | pgsodium 
plpgsql  | 1.0     | pg_catalog

在 PLSQL 中我可以成功地做到..

SELECT pgsodium.crypto_pwhash_str('password');

但是,当我尝试在触发函数中执行相同操作时,我收到错误

ERROR:  function pgsodium.crypto_pwhash_str(text) does not exist
LINE 1: SELECT pgsodium.crypto_pwhash_str(NEW.password)

这就是功能

CREATE OR REPLACE FUNCTION update_user() RETURNS TRIGGER AS $update_user$
BEGIN
    SELECT pgsodium.crypto_pwhash_str(NEW.password) INTO NEW.password;
    RETURN NEW;
END
$update_user$ LANGUAGE plpgsql;

如何执行触发器内的函数?

postgresql triggers
1个回答
0
投票

该函数采用“bytea”类型。

当您执行

SELECT pgsodium.crypto_pwhash_str('password')
时,文字最初被标记为“未知”类型,并且“未知”与“bytea”兼容。它,它会默默地、隐含地将字面解释为字节。

但是密码列已经是已知类型,“文本”。它不会默默地将文本投射到 bytea。您需要添加演员阵容才能实现这一点。像

pgsodium.crypto_pwhash_str(NEW.password::bytea)

之类的东西
© www.soinside.com 2019 - 2024. All rights reserved.