错误:运算符不存在:整数==整数

时间:2017-11-06 01:31:42

标签: sql postgresql

我在postgres函数中使用这些语句。

Select count(*) into V_check
from employee
where employee_name like 'Raj%';

if V_check == 0
then
     update exception set exception_found = 'Raj';
end if;

我收到此错误:

ERROR:  operator does not exist: integer == integer
LINE 1: SELECT V_check == 0

2 个答案:

答案 0 :(得分:4)

您应该使用=代替==

以下是您可以使用的不同比较运算符的列表:

Operator    Description
=   Equal
<>  Not equal. Note: In some versions of SQL this operator may be written as !=
>   Greater than
<   Less than
>=  Greater than or equal
<=  Less than or equal
BETWEEN Between an inclusive range
LIKE    Search for a pattern
IN  To specify multiple possible values for a column

答案 1 :(得分:3)

正如所指出的,相等的比较运算符是=而不是==。但是,您应该将条件写为:

if not exists (select 1 from employee where employee_name like 'Raj%')
then
     update exception
         set exception_found = 'Raj';
end if;

这可以为您节省声明。另外,not existscount(*)快 - 因为not exists可以在第一个匹配的行停止。

完全免除条件:

update exception 
    set exception_found = 'Raj'
    where not exists (select 1 from employee where employee_name like 'Raj%');