gpt4 book ai didi

sql - PostgreSQL 9.3 operator <> 没有给出逻辑结果

转载 作者:行者123 更新时间:2023-11-29 13:18:40 24 4
gpt4 key购买 nike

我在触发器中有这段代码:

CREATE TRIGGER customernametrig
AFTER UPDATE
ON customers
FOR EACH ROW
EXECUTE PROCEDURE trig();

和函数:

CREATE OR REPLACE FUNCTION trig()
RETURNS trigger AS
$BODY$
begin
if TG_OP='UPDATE' then
RAISE NOTICE '%', new.customername;
RAISE NOTICE '%', old.customername;
RAISE NOTICE '%', new.customername<>old.customername;
if new.customername<>old.customername then
RAISE NOTICE 'hi';
end if;
end if;
end;
$BODY$
LANGUAGE plpgsql VOLATILE

customername列是 citext 类型。

当我运行更新命令时

Update customers set customername='Jack' where customerid=125;  

它打印的字段:

NOTICE:  Jack
NOTICE: jack
NOTICE: f

但是如果我运行 select 'jack'<>'Jack'它给了我:t

所以我希望它打印的是:

NOTICE:  Jack
NOTICE: jack
NOTICE: t
NOTICE: hi

我不理解这种行为。这里发生了什么?

最佳答案

https://www.postgresql.org/docs/current/static/citext.html

The citext module provides a case-insensitive character string type

...

citext performs comparisons by converting each string to lower case (as though lower were called) and then comparing the results normally. Thus, for example, two strings are considered equal if lower would produce identical results for them.

t=# select 'jack'<>'Jack';
?column?
----------
t
(1 row)

t=# select 'jack'::citext<>'Jack';
?column?
----------
f
(1 row)

关于sql - PostgreSQL 9.3 operator <> 没有给出逻辑结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45441840/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com