使用crypt创建一个带有密码的新列

发布于 2025-02-01 09:02:53 字数 1378 浏览 3 评论 0原文

我目前正在尝试根据同一表(TB_CUSTOMER)的其他列创建一个带有密码的新列。 创建密码的来源是列Cust_cif。

我使用的脚本如下:

ALTER TABLE erp.tb_customer 
  ADD COLUMN password CHAR (34) USING crypt(erp.tb_customer.cust_cif, gen_salt('md5'));

我遇到了一个错误,并且不知道为什么,因为MD5不需要安装(但是我还是这样)。

错误如下:

ERROR:  does not exist type «crypt»
LINE 2:   ADD COLUMN password crypt(erp.tb_customer.cust_cif, gen_sa...

我还尝试了

ALTER TABLE erp.tb_customer 
  ADD COLUMN password SELECT crypt(erp.tb_customer.cust_cif, gen_salt('md5'));

以下是表中显示的一些值tb_customer

cust_no | cust_name | cust_cif | last_updated_by | last_updated_date

"C0001" "PIENSOS MARTIN"    "A12345678" "SYSTEM"    "2022-04-28"
"C0002" "AGRICULTURA VIVES" "A66666666" "SYSTEM"    "2022-04-28"
"C0003" "CULTIVOS MARAVILLA"    "A55555555" "SYSTEM"    "2022-04-28"
"C0004" "ASOCIADOS PEREZ"   "A23126743" "SYSTEM"    "2022-04-28"
"C0005" "TECNICOS AVA"  "B34211233" "SYSTEM"    "2022-04-28"
"C0006" "AGR AGRI"  "B78788999" "SYSTEM"    "2022-04-28"
"C0007" "AGRIMARCOS"    "B98766562" "SYSTEM"    "2022-04-28"
"C0008" "CULTIVANDO ALEGRIA"    "B12333123" "SYSTEM"    "2022-04-28"
"C0009" "MARCOS LIMPIEZA"   "A87727711" "SYSTEM"    "2022-04-28"
"C0010" "VIAJES MUNDO"  "A00099982" "SYSTEM"    "2022-04-28"

我在做什么错?

先感谢您。

I am currently trying to create a new column with passwords based on other column from the same table (tb_customer).
The source to create the passwords is the column cust_cif.

The script I used is as follows:

ALTER TABLE erp.tb_customer 
  ADD COLUMN password CHAR (34) USING crypt(erp.tb_customer.cust_cif, gen_salt('md5'));

I am getting an error and don't know why, since md5 doesn't need installation (but I did nevertheless).

The error is the following:

ERROR:  does not exist type «crypt»
LINE 2:   ADD COLUMN password crypt(erp.tb_customer.cust_cif, gen_sa...

I also tried with

ALTER TABLE erp.tb_customer 
  ADD COLUMN password SELECT crypt(erp.tb_customer.cust_cif, gen_salt('md5'));

Here are some values shown in the table tb_customer:

cust_no | cust_name | cust_cif | last_updated_by | last_updated_date

"C0001" "PIENSOS MARTIN"    "A12345678" "SYSTEM"    "2022-04-28"
"C0002" "AGRICULTURA VIVES" "A66666666" "SYSTEM"    "2022-04-28"
"C0003" "CULTIVOS MARAVILLA"    "A55555555" "SYSTEM"    "2022-04-28"
"C0004" "ASOCIADOS PEREZ"   "A23126743" "SYSTEM"    "2022-04-28"
"C0005" "TECNICOS AVA"  "B34211233" "SYSTEM"    "2022-04-28"
"C0006" "AGR AGRI"  "B78788999" "SYSTEM"    "2022-04-28"
"C0007" "AGRIMARCOS"    "B98766562" "SYSTEM"    "2022-04-28"
"C0008" "CULTIVANDO ALEGRIA"    "B12333123" "SYSTEM"    "2022-04-28"
"C0009" "MARCOS LIMPIEZA"   "A87727711" "SYSTEM"    "2022-04-28"
"C0010" "VIAJES MUNDO"  "A00099982" "SYSTEM"    "2022-04-28"

What am I doing wrong?

Thank you in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你是暖光i 2025-02-08 09:02:53

没有使用添加列...。

您将必须在不同的语句中添加列并填充它(更新)。可能在同一交易中。

There is no ADD COLUMN...USING.

You will have to add the column and populate it (UPDATE) in different statements. Possibly in the same transaction.

埖埖迣鎅 2025-02-08 09:02:53

我会这样做:

ALTER TABLE erp.tb_customer 
ADD COLUMN password_cryp char(100);

--CREATE EXTENSION pgcrypto;

CREATE OR REPLACE PROCEDURE erp.col_cryp() AS $
DECLARE
  _row record;
BEGIN
    FOR _row IN (
        SELECT cust_cif FROM erp.tb_customer
        )
    LOOP
        UPDATE erp.tb_customer
        SET password_cryp = crypt('cust_cif', gen_salt('md5'));
    END LOOP;
END;
$LANGUAGE plpgsql;

CALL erp.col_cryp();

要测试它,您可以尝试:

SELECT ("password_cryp " = 'copy here the generated code on the table') AS IsMatch FROM erp.tb_customer;

希望它有效!

I would do it this way:

ALTER TABLE erp.tb_customer 
ADD COLUMN password_cryp char(100);

--CREATE EXTENSION pgcrypto;

CREATE OR REPLACE PROCEDURE erp.col_cryp() AS $
DECLARE
  _row record;
BEGIN
    FOR _row IN (
        SELECT cust_cif FROM erp.tb_customer
        )
    LOOP
        UPDATE erp.tb_customer
        SET password_cryp = crypt('cust_cif', gen_salt('md5'));
    END LOOP;
END;
$LANGUAGE plpgsql;

CALL erp.col_cryp();

To test it you can try:

SELECT ("password_cryp " = 'copy here the generated code on the table') AS IsMatch FROM erp.tb_customer;

Hope it works!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文